Last active
February 8, 2016 23:14
-
-
Save gbuesing/a63100bc2a278edfcd0d 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
// declare WKUIDelegate as a delegate for ApplicationController | |
lazy var session: TLSession = { | |
let session = TLSession(webViewConfiguration: self.webViewConfiguration) | |
session.delegate = self | |
session.webView.UIDelegate = self // add this | |
return session | |
}() | |
// MARK: WKUIDelegate | |
func webView(webView: WKWebView, runJavaScriptAlertPanelWithMessage message: String, initiatedByFrame frame: WKFrameInfo, completionHandler: () -> Void) { | |
let alertController = UIAlertController(title: nil, message: message, preferredStyle: .Alert) | |
let defaultAction = UIAlertAction(title: "OK", style: .Default, handler: nil) | |
alertController.addAction(defaultAction) | |
presentViewController(alertController, animated: true, completion: completionHandler) | |
} | |
func webView(webView: WKWebView, runJavaScriptConfirmPanelWithMessage message: String, initiatedByFrame frame: WKFrameInfo, completionHandler: (Bool) -> Void) { | |
let alertController = UIAlertController(title: nil, message: message, preferredStyle: .Alert) | |
let cancelAction = UIAlertAction(title: "Cancel", style: .Default, handler: {(UIAlertAction) in completionHandler(false) }) | |
let confirmAction = UIAlertAction(title: "OK", style: .Default, handler: {(UIAlertAction) in completionHandler(true) }) | |
alertController.addAction(cancelAction) | |
alertController.addAction(confirmAction) | |
presentViewController(alertController, animated: true, completion: nil) | |
} | |
func webView(webView: WKWebView, runJavaScriptTextInputPanelWithPrompt prompt: String, defaultText: String?, initiatedByFrame frame: WKFrameInfo, completionHandler: (String?) -> Void) { | |
let alertController = UIAlertController(title: nil, message: prompt, preferredStyle: .Alert) | |
let cancelAction = UIAlertAction(title: "Cancel", style: .Default, handler: {(UIAlertAction) in completionHandler(nil)}) | |
let confirmAction = UIAlertAction(title: "OK", style: .Default, handler: {(UIAlertAction) in | |
let textField = alertController.textFields![0] as UITextField | |
completionHandler(textField.text) | |
}) | |
alertController.addTextFieldWithConfigurationHandler({(textField) in textField.text = defaultText}) | |
alertController.addAction(cancelAction) | |
alertController.addAction(confirmAction) | |
presentViewController(alertController, animated: true, completion: nil) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment