File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -66,14 +66,17 @@ class ViewController: UIViewController {
6666 // Create javaScriptController.
6767 let javaScriptController = WKJavaScriptController (name : " native" , target : self , bridgeProtocol : JavaScriptInterface.self )
6868
69- // Add your javascript.
69+ // [Optional] Add your javascript.
7070 let jsString = ...
7171 let userScript = WKUserScript (source : jsString, injectionTime : .AtDocumentEnd , forMainFrameOnly : true )
7272 javaScriptController.addUserScript (userScript)
7373
7474 let webView = WKWebView (... )
7575 ...
7676
77+ // Assign javaScriptController.
78+ webView.javaScriptController = javaScriptController
79+
7780 // Call prepareForJavaScriptController before initializing WKWebView or loading page.
7881 webView.prepareForJavaScriptController ()
7982 webView.loadRequest (... )
You can’t perform that action at this time.
0 commit comments