Skip to content

Instantly share code, notes, and snippets.

@chuganzy
Last active December 12, 2015 22:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chuganzy/acc59af0e04bf31188dc to your computer and use it in GitHub Desktop.
Save chuganzy/acc59af0e04bf31188dc to your computer and use it in GitHub Desktop.
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