Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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