WkWebView设置可以应用内下载安装app

实现WKwebview的代理,然后在此代理从填写这个

/** 在发送请求之前,决定是否跳转 */
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
   
    WKNavigationActionPolicy policy =WKNavigationActionPolicyAllow;
    NSSet *validSchemes = [NSSet setWithArray:@[@"http", @"https"]];
    if(![validSchemes containsObject:navigationAction.request.URL.scheme]) {
       
        [[UIApplication sharedApplication] openURL:navigationAction.request.URL];
        policy =WKNavigationActionPolicyCancel;
    }else if([[navigationAction.request.URL host] isEqualToString:@"itunes.apple.com"] &&[[UIApplication sharedApplication] openURL:navigationAction.request.URL]){
        policy =WKNavigationActionPolicyCancel;
    }
    if (navigationAction.targetFrame == nil) {
        [webView loadRequest:navigationAction.request];
    }
    decisionHandler(policy);


//    decisionHandler(WKNavigationActionPolicyAllow);
}

你可能感兴趣的:(WkWebView设置可以应用内下载安装app)