美文网首页
ios WKWebView中拦截点击按钮事件跳转appstor

ios WKWebView中拦截点击按钮事件跳转appstor

作者: 江湖闹士 | 来源:发表于2023-06-01 11:49 被阅读0次
    -(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);
    }
    

    相关文章

      网友评论

          本文标题:ios WKWebView中拦截点击按钮事件跳转appstor

          本文链接:https://www.haomeiwen.com/subject/jwmuedtx.html