mirror of
https://github.com/scratchfoundation/scratchjr.git
synced 2024-11-28 10:05:59 -05:00
iOS: open external link in browser
This commit is contained in:
parent
96ce9b0641
commit
97b46b479e
1 changed files with 18 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue