在webview的代理方法中的拦截器中进行配置
-(void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler{
if(webView != self.webView) {
decisionHandler(WKNavigationActionPolicyAllow);
return;
}
NSURL * url = navigationAction.request.URL;
UIApplication *app = [UIApplication sharedApplication];
// appstorte
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.webView loadRequest:navigationAction.request];
}
// appstore的外的包
if ([url.absoluteString containsString:@"itms-services://"]) {
[app openURL:url options:@{} completionHandler:^(BOOL success) {
}];
decisionHandler(WKNavigationActionPolicyCancel);
return;
}
decisionHandler(WKNavigationActionPolicyAllow);
}