iOS 11.3 WKWebView:input.focus()不做任何事情

时间:2018-03-31 12:40:43

标签: javascript html ios safari wkwebview

自更新到iOS 11.3以来,HTML输入字段无法再使用JavaScript .focus()进行聚焦,除非函数调用紧跟触摸交互(以前可以使用.focus())。有没有已知的解决方法?

4 个答案:

答案 0 :(得分:1)

blur() .....

之前致电focus()

答案 1 :(得分:0)

似乎已将某些更新推送到回购:

https://github.com/ionic-team/cordova-plugin-wkwebview-engine/pull/171#issuecomment-377824347

因此,请确保删除cordova ios平台,添加最新版本的wkwebview:cordova-plugin-ionic-webview 1.1.19,然后添加npm install并添加平台ios。我刚刚测试它就像一个魅力。

答案 2 :(得分:0)

向元素添加点击功能以调用焦点功能工作正常。或者更好的解决方案?

AlarmManager

答案 3 :(得分:0)

这是我们当前在应用程序开发框架中使用的代码,以使input.focus()正常工作。确认可正常使用并被Apple在App Store中接受:

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);
}