func webView(webView: WKWebView, runJavaScriptAlertPanelWithMessage message: String, initiatedByFrame frame: WKFrameInfo, completionHandler: () -> Void) {
if let host = self.webkitWebView?.URL?.host{
var alertController = UIAlertController(title: self.webkitWebView?.URL?.host, message: message, preferredStyle: .Alert)
alertController.addAction(UIAlertAction(title: "Close", style: UIAlertActionStyle.Cancel, handler: {[unowned self] (action: UIAlertAction!) in
completionHandler()
}))
self.presentViewController(alertController, animated: true, completion: nil)
}
}
func webView(webView: WKWebView, runJavaScriptConfirmPanelWithMessage message: String, initiatedByFrame frame: WKFrameInfo, completionHandler: (Bool) -> Void) {
if let host = self.webkitWebView?.URL?.host{
let alertController = UIAlertController(title: host, message: message, preferredStyle: .Alert)
alertController.addAction(UIAlertAction(title: "OK", style: .Default, handler: {[unowned self] (action: UIAlertAction!) in
completionHandler(true)
}))
alertController.addAction(UIAlertAction(title: "Cancel", style: .Cancel, handler: {[unowned self] (action: UIAlertAction!) in
completionHandler(false)
}))
self.presentViewController(alertController, animated: true, completion: nil)
}
}
func webView(webView: WKWebView, runJavaScriptTextInputPanelWithPrompt prompt: String, defaultText: String?, initiatedByFrame frame: WKFrameInfo, completionHandler: (String!) -> Void) {
if let host = self.webkitWebView?.URL?.host{
let alertController = UIAlertController(title: prompt, message: self.webkitWebView?.URL?.host, preferredStyle: .Alert)
alertController.addTextFieldWithConfigurationHandler({[unowned self] (textField: UITextField!) in
textField.text = defaultText
})
alertController.addAction(UIAlertAction(title: "OK", style: .Default, handler: {[unowned self] (action: UIAlertAction!) in
let input = (alertController.textFields?.first as? UITextField)?.text
completionHandler(input)
}))
alertController.addAction(UIAlertAction(title: "Cancel", style: .Default, handler: {[unowned self] (action: UIAlertAction!) in
completionHandler(nil)
}))
self.presentViewController(alertController, animated: true, completion: nil)
}
}