@@ -17,27 +17,28 @@ import WKJavaScriptController
1717extension ViewController : JavaScriptInterface {
1818 func onSubmit( _ dictonary: [ String : AnyObject ] ) {
1919 NSLog ( " onSubmit \( dictonary) " )
20- isSubmitted = true
20+ _isSubmitted = true
2121 }
2222
2323 func onSubmit( _ dictonary: [ String : AnyObject ] , clear: JSBool ) {
2424 NSLog ( " onSubmit \( dictonary) " )
2525 if clear. value {
2626 webView. evaluateJavaScript ( " clearAll() " , completionHandler: nil )
2727 }
28- isSubmitted = true
28+ _isSubmitted = true
2929 }
3030
3131 func onSubmit( _ email: String , firstName: String , lastName: String , address1: String , address2: String , zipCode: JSInt , phoneNumber: String ) {
3232 NSLog ( " onSubmit \( email) , \( firstName) , \( lastName) , \( address1) , \( address2) , \( zipCode. value) , \( phoneNumber) " )
33- isSubmitted = true
33+ _isSubmitted = true
3434 }
3535
3636 func onCancel( ) {
3737 NSLog ( " onCancel " )
38+ _isSubmitted = false
3839 }
3940
40- var isSubmitted : JSBool { JSBool ( isSubmitted ) }
41+ var isSubmitted : JSBool { JSBool ( _isSubmitted ) }
4142
4243 func getErrorMessages( codes: [ JSInt ] ) -> [ String ] {
4344 codes. map { " message \( $0) " }
@@ -47,7 +48,7 @@ extension ViewController: JavaScriptInterface {
4748class ViewController : UIViewController {
4849 fileprivate var webView : WKWebView !
4950
50- private var isSubmitted = false
51+ private var _isSubmitted = false
5152
5253 override func viewDidAppear( _ animated: Bool ) {
5354 super. viewDidAppear ( animated)
@@ -63,6 +64,7 @@ class ViewController: UIViewController {
6364 javaScriptController. addUserScript ( userScript)
6465
6566 webView = WKWebView ( frame: view. frame)
67+ webView. uiDelegate = self
6668 view. addSubview ( webView)
6769
6870 // Assign javaScriptController.
@@ -75,3 +77,13 @@ class ViewController: UIViewController {
7577 }
7678 }
7779}
80+
81+ extension ViewController : WKUIDelegate {
82+ func webView( _ webView: WKWebView , runJavaScriptAlertPanelWithMessage message: String , initiatedByFrame frame: WKFrameInfo , completionHandler: @escaping ( ) -> Void ) {
83+ let alertController = UIAlertController ( title: nil , message: message, preferredStyle: . alert)
84+ alertController. addAction ( UIAlertAction ( title: " OK " , style: . default, handler: { _ in
85+ completionHandler ( )
86+ } ) )
87+ present ( alertController, animated: true , completion: nil )
88+ }
89+ }
0 commit comments