所以我正在将我的UIWebView应用程序转换为WKWebView只是为了发现它不会打开外部网站,即dropbox,facebook等.
它在viewDidLoad中加载我的网站,所以这不是问题.
例:
NSURL *nsurl=[NSURL URLWithString:@"example.com"]; NSURLRequest *nsrequest=[NSURLRequest requestWithURL:nsurl]; [webView loadRequest:nsrequest]; webView.navigationDelegate = self; webView.UIDelegate = self; [self.view addSubview:webView];
我打过电话:
-(void)webView:(WKWebView *)webView didStartProvisionalNavigation: (WKNavigation *)navigation {} - (void)webView:(WKWebView *)webView didFinishNavigation: (WKNavigation *)navigation{}
随着:
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {} decisionHandler(WKNavigationActionPolicyAllow);
最后在我的info.plist中我添加了:
NSAppTransportSecurity NSAllowsArbitraryLoads NSExceptionAllowsInsecureHTTPLoads NSIncludesSubdomains NSThirdPartyExceptionAllowsInsecureHTTPLoads
但没有任何作用.我究竟做错了什么?
任何帮助都将一如既往地受到高度赞赏.
好吧所以我设法得到它,以及一些被遗忘的网站的一些帮助(抱歉)我设法让它全部工作.
所以下面几乎是我在webview中使用的所有内容.
//Webview Start/Finish Request - (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation { [UIApplication sharedApplication].networkActivityIndicatorVisible = YES; NSLog(@"didStartProvisionalNavigation: %@", navigation); } - (void)webView:(WKWebView *)webView didReceiveServerRedirectForProvisionalNavigation:(WKNavigation *)navigation { NSLog(@"didReceiveServerRedirectForProvisionalNavigation: %@", navigation); } - (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation withError:(NSError *)error { NSLog(@"didFailProvisionalNavigation: %@navigation, error: %@", navigation, error); } - (void)webView:(WKWebView *)webView didCommitNavigation:(WKNavigation *)navigation { NSLog(@"didCommitNavigation: %@", navigation); } - (void)webView:(WKWebView *)webView didFinishLoadingNavigation:(WKNavigation *)navigation { [UIApplication sharedApplication].networkActivityIndicatorVisible = NO; NSLog(@"didFinishLoadingNavigation: %@", navigation); } - (void)webView:(WKWebView *)webView didFailNavigation:(WKNavigation *)navigation withError:(NSError *)error { NSLog(@"didFailNavigation: %@, error %@", navigation, error); } - (void)_webViewWebProcessDidCrash:(WKWebView *)webView { NSLog(@"WebContent process crashed; reloading"); } - (WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures { if (!navigationAction.targetFrame.isMainFrame) { [UIApplication sharedApplication].networkActivityIndicatorVisible = YES; [self.webView loadRequest:navigationAction.request]; } return nil; } - (void)webView:(WKWebView *)webView didFinishNavigation: (WKNavigation *)navigation{ [UIApplication sharedApplication].networkActivityIndicatorVisible = NO; NSLog(@"didFinish: %@; stillLoading:%@", [self.webView URL], (self.webView.loading?@"NO":@"YES")); } - (void)webView:(WKWebView *)webView decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler { NSLog(@"decidePolicyForNavigationResponse"); decisionHandler(WKNavigationResponsePolicyAllow); } - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler { if (decisionHandler) { decisionHandler(WKNavigationActionPolicyAllow); } }
所以我帮助所有这些帮助某人.