diff --git a/package.json b/package.json index 270053c..94f170e 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "url": "git+https://github.com/onderceylan/cordova-plugin-wkwebview-inputfocusfix" }, "name": "cordova-plugin-wkwebview-inputfocusfix", - "version": "1.0.1", + "version": "1.0.2", "description": "Cordova plugin for fixing auto focus issue of html elements on WKWebView", "cordova": { "id": "cordova-plugin-wkwebview-inputfocusfix", @@ -32,4 +32,4 @@ } } } -} \ No newline at end of file +} diff --git a/src/ios/CDVWKWebViewEngine+InputFocusFix.m b/src/ios/CDVWKWebViewEngine+InputFocusFix.m index 185ac74..b82e5fa 100644 --- a/src/ios/CDVWKWebViewEngine+InputFocusFix.m +++ b/src/ios/CDVWKWebViewEngine+InputFocusFix.m @@ -1,4 +1,5 @@ #import "CDVWKWebViewEngine+InputFocusFix.h" +#import @implementation CDVWKWebViewEngine (InputFocusFix) + (void) load { @@ -17,14 +18,27 @@ - (void) swizzleWKContentViewForInputFocus { } // https://github.com/Telerik-Verified-Plugins/WKWebView/commit/04e8296adeb61f289f9c698045c19b62d080c7e3 +// https://stackoverflow.com/a/48623286/3297914 - (void) keyboardDisplayDoesNotRequireUserAction { - SEL sel = sel_getUid("_startAssistingNode:userIsInteracting:blurPreviousNode:userObject:"); - Class WKContentView = NSClassFromString(@"WKContentView"); - Method method = class_getInstanceMethod(WKContentView, sel); - IMP originalImp = method_getImplementation(method); - IMP imp = imp_implementationWithBlock(^void(id me, void* arg0, BOOL arg1, BOOL arg2, id arg3) { - ((void (*)(id, SEL, void*, BOOL, BOOL, id))originalImp)(me, sel, arg0, TRUE, arg2, arg3); - }); - method_setImplementation(method, imp); + Class class = NSClassFromString(@"WKContentView"); + NSOperatingSystemVersion iOS_11_3_0 = (NSOperatingSystemVersion){11, 3, 0}; + + if ([[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion: iOS_11_3_0]) { + SEL selector = sel_getUid("_startAssistingNode:userIsInteracting:blurPreviousNode:changingActivityState:userObject:"); + Method method = class_getInstanceMethod(class, selector); + IMP original = method_getImplementation(method); + IMP override = imp_implementationWithBlock(^void(id me, void* arg0, BOOL arg1, BOOL arg2, BOOL arg3, id arg4) { + ((void (*)(id, SEL, void*, BOOL, BOOL, BOOL, id))original)(me, selector, arg0, TRUE, arg2, arg3, arg4); + }); + method_setImplementation(method, override); + } else { + SEL selector = sel_getUid("_startAssistingNode:userIsInteracting:blurPreviousNode:userObject:"); + Method method = class_getInstanceMethod(class, selector); + IMP original = method_getImplementation(method); + IMP override = imp_implementationWithBlock(^void(id me, void* arg0, BOOL arg1, BOOL arg2, id arg3) { + ((void (*)(id, SEL, void*, BOOL, BOOL, id))original)(me, selector, arg0, TRUE, arg2, arg3); + }); + method_setImplementation(method, override); + } } -@end \ No newline at end of file +@end