Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

同样的脚本在 iOS 11.3 和ios 11 转换出来的代码不一样 #825

Open
xiaodai opened this issue May 23, 2018 · 2 comments
Open

Comments

@xiaodai
Copy link

xiaodai commented May 23, 2018

OC 方法
-(void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler
{
NSURL *url = navigationAction.request.URL;
if ([url.scheme isEqualToString:@"weixin"] || [url.scheme isEqualToString:@"alipay"]) {
if ( [[UIApplication sharedApplication] canOpenURL:url]) {
if (@available(iOS 10.0, *)) {
[[UIApplication sharedApplication] openURL:url options:@{UIApplicationOpenURLOptionUniversalLinksOnly: @no} completionHandler:nil];
} else {
[[UIApplication sharedApplication] openURL:url];
}
decisionHandler(WKNavigationActionPolicyCancel);
return;
}
}
decisionHandler(WKNavigationActionPolicyAllow);
}

脚本如下
defineClass("LYWebViewController", {
webView_decidePolicyForNavigationAction_decisionHandler: function (webView, navigationAction,decisionHandler) {
var url = navigationAction.request().URL();
if (url.scheme().isEqualToString("weixin") || url.scheme().isEqualToString("alipay")) {
if (UIApplication.sharedApplication().canOpenURL(url)) {
if (UIDevice.currentDevice().systemVersion().floatValue() >= 10) {
UIApplication.sharedApplication().openURL_options_completionHandler(url, {
UIApplicationOpenURLOptionUniversalLinksOnly: NO
}, null);
} else {
UIApplication.sharedApplication().openURL(url);
}
decisionHandler(0);
return;
}
}
decisionHandler(1);
}
}, {});

ios 11 正常执行,ios 11.3 脚本报错,说decisionHandler不是函数,是个object

@nidom
Copy link

nidom commented Jul 13, 2018

我也遇到了相同的问题 请问解决了吗

@bang590
Copy link
Owner

bang590 commented Jul 13, 2018

试试

if (typeof decisionHandler == 'function') {
decisionHandler(0);
}
if (typeof decisionHandler == 'function') {
decisionHandler(1);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants