Last active
December 12, 2015 22:11
-
-
Save chuganzy/acc59af0e04bf31188dc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool { | |
guard let url = request.URL else { | |
return true | |
} | |
if url.scheme.rangeOfString("^https?", options: .RegularExpressionSearch) != nil { | |
return true | |
} | |
if !UIApplication.sharedApplication().canOpenURL(url) { | |
// iOS9でInfo.plistに登録してないとfalseになるのでここに来る | |
return false | |
} | |
let ac = UIAlertController(title: "", message: "Open \(url.absoluteString)?", preferredStyle: .Alert) | |
ac.addAction(UIAlertAction(title: "No", style: .Cancel, handler: nil)) | |
ac.addAction(UIAlertAction(title: "Yes", style: .Default) { (_) -> Void in | |
UIApplication.sharedApplication().openURL(url) | |
}) | |
presentViewController(ac, animated: true, completion: nil) | |
return false | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment