實(shí)現(xiàn)WKNavigationDelegate代理方法
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
WKNavigationActionPolicy policy =WKNavigationActionPolicyAllow;
NSString *strRequest = [navigationAction.request.URL.absoluteString stringByRemovingPercentEncoding];
strRequest = [strRequest stringByReplacingOccurrencesOfString:@"http:///" withString:@"http://"];
// 在App Store中下載
if([[navigationAction.request.URL host] isEqualToString:@"itunes.apple.com"] && [[UIApplication sharedApplication] openURL:navigationAction.request.URL] ){
policy = WKNavigationActionPolicyCancel;
}
// 企業(yè)證書App通用前綴
NSString *hasPrefix = @"itms-services://?action=download-manifest&url=";
// 下載其他產(chǎn)品app
if ([strRequest containsString:hasPrefix]) {
/**
url 后面的鏈接地址https://download.fir.im/apps/xxx/install?download_token=xxxxxx,
需要 URLEncode 成 https%3A%2F%2Fdownload.fir.im%2Fapps%2F%3Aid%2Finstall%3Fdownload_token%3Dxxxxxx
*/
NSRange range = [strRequest rangeOfString:hasPrefix];
NSString *str = [strRequest substringFromIndex:range.length];
// 轉(zhuǎn)碼后的地址
[self openDownLoadUrl:[NSString stringWithFormat:@"%@%@", hasPrefix, [str encodeString]]];
}
// 若是安裝描述文件證書音诫,退出當(dāng)前控制器
if ([strRequest hasSuffix:@".mobileprovision"]) {
[self.navigationController popViewControllerAnimated:YES];
}
decisionHandler(policy);
}