Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@gbuesing
Last active February 8, 2016 23:14
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 gbuesing/a63100bc2a278edfcd0d to your computer and use it in GitHub Desktop.
Save gbuesing/a63100bc2a278edfcd0d to your computer and use it in GitHub Desktop.
// 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