-(void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler{
if(webView != self.wkWebView) {
decisionHandler(WKNavigationActionPolicyAllow);
return;
}
NSURL * url = navigationAction.request.URL;
UIApplication *app = [UIApplication sharedApplication];
// appstore
if ([url.absoluteString containsString:@"itunes.apple.com"]) {
if ([app canOpenURL:url]){
[app openURL:url options:@{} completionHandler:^(BOOL success) {
}];
decisionHandler(WKNavigationActionPolicyCancel);
return;
}
}
if (!navigationAction.targetFrame.isMainFrame) {
[self.wkWebView loadRequest:navigationAction.request];
}
// appstore的外的包 慎用 itms-services ----审核会被拒
if ([url.absoluteString containsString:@"itms-services://"]) {
[app openURL:url options:@{} completionHandler:^(BOOL success) {
}];
decisionHandler(WKNavigationActionPolicyCancel);
return;
}
decisionHandler(WKNavigationActionPolicyAllow);
}
网友评论