Javascript iOS 11.3 WKWebView:input.focus()不';我什么也不做

Javascript iOS 11.3 WKWebView:input.focus()不';我什么也不做,javascript,html,ios,safari,wkwebview,Javascript,Html,Ios,Safari,Wkwebview,由于更新到iOS 11.3,HTML输入字段不能再使用JavaScript.focus()聚焦,除非函数调用紧跟在触摸交互之后(过去可以随时使用.focus())。是否有已知的解决方法?似乎他们已被推送到回购协议的一些更新: 因此,请确保删除cordova ios平台,添加最新版本的wkwebview:cordova插件ionic webview 1.1.19,然后添加npm安装和添加平台ios。我刚刚测试了它的工作原理。将click函数添加到元素以调用focus函数很好。还是有更好的解决办法

由于更新到iOS 11.3,HTML输入字段不能再使用JavaScript.focus()聚焦,除非函数调用紧跟在触摸交互之后(过去可以随时使用.focus())。是否有已知的解决方法?

似乎他们已被推送到回购协议的一些更新:


因此,请确保删除cordova ios平台,添加最新版本的wkwebview:cordova插件ionic webview 1.1.19,然后添加npm安装和添加平台ios。我刚刚测试了它的工作原理。将click函数添加到元素以调用focus函数很好。还是有更好的解决办法

<html>
<head>
        <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">

        <meta charset="UTF-8">
        <meta name="apple-mobile-web-app-capable" content="yes" />
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <meta name="format-detection" content="telephone=no, email=no">            
</head>
<body>
    <input id="test" type="text" placeholder="test" />
    <input id="test2" type="text" placeholder="test" />

    <script src="https://cdn.bootcss.com/fastclick/1.0.6/fastclick.js"></script>
    <script>
        window.FastClick.attach(document.body);
        document.getElementById('test').onclick = function(e) {
          // works fine
          e.target.focus();
        };
        document.getElementById('test2').onclick = function(e) {
          // not working
          setTimeout(function() {
            e.target.focus();
          }, 50)
        };
    </script>
</body>
</html>

window.FastClick.attach(document.body);
document.getElementById('test')。onclick=function(e){
//很好
e、 target.focus();
};
document.getElementById('test2')。onclick=function(e){
//不起作用
setTimeout(函数(){
e、 target.focus();
}, 50)
};

focus()
之前调用
blur()

以下是我们目前在应用程序开发框架中用于输入的代码。focus()有效。苹果已确认在应用商店工作并接受:

Class class = NSClassFromString(@"WKContentView");
NSOperatingSystemVersion iOS_11_3_0 = (NSOperatingSystemVersion){11, 3, 0};
NSOperatingSystemVersion iOS_12_2_0 = (NSOperatingSystemVersion){12, 2, 0};
NSOperatingSystemVersion iOS_13_0_0 = (NSOperatingSystemVersion){13, 0, 0};

if ([[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion: iOS_13_0_0]) {
    SEL selector = sel_getUid("_elementDidFocus:userIsInteracting:blurPreviousNode:activityStateChanges: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 if ([[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion: iOS_12_2_0]) {
    SEL selector = sel_getUid("_elementDidFocus: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 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);
}

我没有使用Cordova,但在谷歌搜索了很多次之后,我已经找到了一种新的方法来使用相关的WebKit功能。无论如何,非常感谢@SevenSystems您能分享一下您找到的解决方案吗?我们也不使用Cordova,到目前为止还没有解决这个问题。你能解释一下你的答案吗?只需添加onclick来触发focusHello Seven,你能告诉我你在代码库的什么地方插入了这些行吗?谢谢。你好,路易斯——在初始化WKWebView之后。但是,从那时起,代码已扩展到较新的iOS版本。。。现在将更新它。