Skip to content

Commit 3a4e790

Browse files
authored
Merge pull request onderceylan#4 from Hirbod/patch-1
Fix for iOS 11.3
2 parents 714974f + 266747c commit 3a4e790

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"url": "git+https://github.com/onderceylan/cordova-plugin-wkwebview-inputfocusfix"
99
},
1010
"name": "cordova-plugin-wkwebview-inputfocusfix",
11-
"version": "1.0.1",
11+
"version": "1.0.2",
1212
"description": "Cordova plugin for fixing auto focus issue of html elements on WKWebView",
1313
"cordova": {
1414
"id": "cordova-plugin-wkwebview-inputfocusfix",
@@ -32,4 +32,4 @@
3232
}
3333
}
3434
}
35-
}
35+
}

src/ios/CDVWKWebViewEngine+InputFocusFix.m

+23-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#import "CDVWKWebViewEngine+InputFocusFix.h"
2+
#import <objc/runtime.h>
23

34
@implementation CDVWKWebViewEngine (InputFocusFix)
45
+ (void) load {
@@ -17,14 +18,27 @@ - (void) swizzleWKContentViewForInputFocus {
1718
}
1819

1920
// https://github.com/Telerik-Verified-Plugins/WKWebView/commit/04e8296adeb61f289f9c698045c19b62d080c7e3
21+
// https://stackoverflow.com/a/48623286/3297914
2022
- (void) keyboardDisplayDoesNotRequireUserAction {
21-
SEL sel = sel_getUid("_startAssistingNode:userIsInteracting:blurPreviousNode:userObject:");
22-
Class WKContentView = NSClassFromString(@"WKContentView");
23-
Method method = class_getInstanceMethod(WKContentView, sel);
24-
IMP originalImp = method_getImplementation(method);
25-
IMP imp = imp_implementationWithBlock(^void(id me, void* arg0, BOOL arg1, BOOL arg2, id arg3) {
26-
((void (*)(id, SEL, void*, BOOL, BOOL, id))originalImp)(me, sel, arg0, TRUE, arg2, arg3);
27-
});
28-
method_setImplementation(method, imp);
23+
Class class = NSClassFromString(@"WKContentView");
24+
NSOperatingSystemVersion iOS_11_3_0 = (NSOperatingSystemVersion){11, 3, 0};
25+
26+
if ([[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion: iOS_11_3_0]) {
27+
SEL selector = sel_getUid("_startAssistingNode:userIsInteracting:blurPreviousNode:changingActivityState:userObject:");
28+
Method method = class_getInstanceMethod(class, selector);
29+
IMP original = method_getImplementation(method);
30+
IMP override = imp_implementationWithBlock(^void(id me, void* arg0, BOOL arg1, BOOL arg2, BOOL arg3, id arg4) {
31+
((void (*)(id, SEL, void*, BOOL, BOOL, BOOL, id))original)(me, selector, arg0, TRUE, arg2, arg3, arg4);
32+
});
33+
method_setImplementation(method, override);
34+
} else {
35+
SEL selector = sel_getUid("_startAssistingNode:userIsInteracting:blurPreviousNode:userObject:");
36+
Method method = class_getInstanceMethod(class, selector);
37+
IMP original = method_getImplementation(method);
38+
IMP override = imp_implementationWithBlock(^void(id me, void* arg0, BOOL arg1, BOOL arg2, id arg3) {
39+
((void (*)(id, SEL, void*, BOOL, BOOL, id))original)(me, selector, arg0, TRUE, arg2, arg3);
40+
});
41+
method_setImplementation(method, override);
42+
}
2943
}
30-
@end
44+
@end

0 commit comments

Comments
 (0)