I'm having code which perfectly works in iOS 9, but not working in iOS 10, specifically doBar() not called. Here in WKWebView I'm injecting javascript code.
let jsFoo = "function doFoo() { window.webkit.messageHandlers.doFoo.postMessage(\"doFoo\"); }"
let jsBar = "class MyInterface { static doBar() { window.webkit.messageHandlers.doBar.postMessage(\"doBar\"); } }"
let fooScript = WKUserScript(source: jsFoo, injectionTime: .atDocumentEnd, forMainFrameOnly: true)
let barScript = WKUserScript(source: jsBar, injectionTime: .atDocumentEnd, forMainFrameOnly: true)
contentController.addUserScript(logoutScript)
contentController.addUserScript(openPDFScript)
contentController.add(self, name: "doFoo")
contentController.add(self, name: "doBar")
In web page js code make calls:
window.doFoo() // works in both iOS 9 and iOS 10
window.MyInterface.doBar() // works in iOS 9, but NOT working in iOS 10
Safari debugger shows that in iOS 10 window.MyInterface is undefined, however user-script with doBar code is present.
How can I inject doBar properly, so it will work in iOS 10, assuming that web code I can't change?