Merge pull request #487 from yueyuzhao/issue/643-open-external-link

iOS: open external link in browser
This commit is contained in:
chrisgarrity 2021-08-10 15:59:21 -04:00 committed by GitHub
commit a52ede4469
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -197,6 +197,24 @@ NSDate *startDate;
});
}
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
// All internal urls are started with file:///, if the url scheme is http or https,
// the app is trying to open an external link, we should open it in the browser.
// For now, only the PBS edition opens an itunes link in the lobby.
// If we are going to support more shemes like opening other apps or ftp etc,
// this is the right place to go.
NSURL *url = navigationAction.request.URL;
NSString *scheme = url.scheme;
if ([scheme isEqualToString:@"http"] || [scheme isEqualToString:@"https"]) {
if ([UIApplication.sharedApplication canOpenURL:url]) {
[UIApplication.sharedApplication openURL:url options:@{} completionHandler:nil];
}
decisionHandler(WKNavigationActionPolicyCancel);
return;
}
decisionHandler(WKNavigationActionPolicyAllow);
}
// Sharing controllers - if we later decide to unify, use UIActivityViewController
// Email sharing