lundi 21 décembre 2015

WKWebView won't open external links

So I was in the process of converting my UIWebView app over to WKWebView only to find out that it won't open external websites, i.e. dropbox, facebook etc.

Obviously it loads my site in the viewDidLoad, so that's not an issue.

example:

NSURL *nsurl=[NSURL URLWithString:@"example.com"];
NSURLRequest *nsrequest=[NSURLRequest requestWithURL:nsurl];
[webView loadRequest:nsrequest];

webView.navigationDelegate = self;
webView.UIDelegate = self;
[self.view addSubview:webView];

I have called:

-(void)webView:(WKWebView *)webView didStartProvisionalNavigation: (WKNavigation *)navigation {}

- (void)webView:(WKWebView *)webView didFinishNavigation: (WKNavigation *)navigation{}

along with:

- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {}

decisionHandler(WKNavigationActionPolicyAllow);

and finally in my info.plist I added:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
    <key>NSExceptionAllowsInsecureHTTPLoads</key>
    <true/>
    <key>NSIncludesSubdomains</key>
    <true/>
    <key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key>
    <true/>
</dict>

Yet nothing works. What am I doing wrong?

Any help would as always be greatly appreciated.




1 commentaire: