Closed saraht129 closed 8 years ago
I'm on it. Give me just a few hours please - gotta make coffee first :)
-- while mobile
On Tue, Feb 2, 2016 at 9:37 AM, saraht129 notifications@github.com wrote:
Hi there, I'm developing with Swift, WKWebView and iOS 9. I was using v4.1.5 and the bridging works fine. After upgrading to 5.0.1, the JS side failed to retrieve response from Swift. I have update my JS file according to your doc: function setupWebViewJavascriptBridge(callback) { if (window.WebViewJavascriptBridge) { return callback(WebViewJavascriptBridge); } if (window.WVJBCallbacks) { return window.WVJBCallbacks.push(callback); } window.WVJBCallbacks = [callback]; var WVJBIframe = document.createElement('iframe'); WVJBIframe.style.display = 'none'; WVJBIframe.src = 'wvjbscheme://BRIDGE_LOADED'; document.documentElement.appendChild(WVJBIframe); setTimeout(function() { document.documentElement.removeChild(WVJBIframe) }, 0) } I am also able to see the logs of send / receive activity on my Xcode console: 2016-02-02 22:32:34.052 MyApp[42991:413976] WVJB RCVD: { "handlerName" : "myHandler" } The app is able to stop at the breakpoint i place on my
registerHandler
line: self.bridge?.registerHandler("myHandler", handler: {[unowned self](data: AnyObject!, callback: WVJBResponseCallback!) -> Void in callback(self.myHandler()) }) But the JS just doesn't get the data returned onself.myHandler()
, the console also didn't print any response log. What have I missed here? Thanks! Some investigations:
self.bridge
is notnil
2. 1self.bridge?.callHandler("jsHandler")` works fine
Reply to this email directly or view it on GitHub: https://github.com/marcuswestin/WebViewJavascriptBridge/issues/184
Thanks for the quick response :) Enjoy your coffee
@saraht129: I've added a test to ensure that the JS does indeed get values returned by the ObjC side of things. Here are the relevant lines:
ObjC responding to JS: https://github.com/marcuswestin/WebViewJavascriptBridge/blob/5e40fefddd790c31d162c6a71976e2942f275ea9/Tests/WebViewJavascriptBridgeTests/BridgeTests.m#L134
Javascript that checks the return value from ObjC: https://github.com/marcuswestin/WebViewJavascriptBridge/blob/5e40fefddd790c31d162c6a71976e2942f275ea9/Tests/WebViewJavascriptBridgeTests/echo.html#L24
I can help you debug the issue if you're able to reproduce it for me :)
Cheers, Marcus
Also worth noting: the latest version is 5.0.2 as of a few days ago :)
Thanks for the response. I found the source of the issue, which is a reckless mistake:
The callHandler
on my JS missed the data
field:
bridge.callHandler("myHandler", function (response){ })
(I misread your doc when updating my JS for 5.0.1)
Changing it back to bridge.callHandler("myHandler", null, function (response){ })
fixes the whole thing.
Thanks man :)
Ah. The library could definitely be more helpful there! We should probably handle both cases properly. Adding to roadmap. Cheers!
-- while mobile
On Tue, Feb 2, 2016 at 11:17 AM, saraht129 notifications@github.com wrote:
Closed #184.
Reply to this email directly or view it on GitHub: https://github.com/marcuswestin/WebViewJavascriptBridge/issues/184#event-536076096
Hi there, I'm developing with Swift, WKWebView and iOS 9. I was using v4.1.5 and the bridging works fine. After upgrading to 5.0.1, the JS side failed to retrieve response from Swift.
I have updated my JS file according to your doc:
I am also able to see the logs of send / receive activity on my Xcode console:
The app is able to stop at the breakpoint i place on my
registerHandler
line:But the JS just doesn't get the data returned on
self.myHandler()
, the console also doesn't print any response log.What have I missed here? Thanks!
Some investigations:
self.bridge
is notnil
self.bridge?.callHandler("jsHandler")
works fine