ShawnFoo / SwiftWebViewBridge

Swift version of WebViewJavascriptBridge with more simplified and friendly methods to handle messages between Swift and JS in UIWebViews
MIT License
137 stars 34 forks source link

Callback not firing #4

Closed ksabariraj closed 8 years ago

ksabariraj commented 8 years ago

Hi,

Thanks for the code.

when I'm trying to run your code always default callback is executing. Can you please help me on this?

Thanks.

ShawnFoo commented 8 years ago

Hi, I have downloaded and tested my latest release from git(Builded on Xcode7.3.1). But couldn't repeat your case.

Could you please offer more infos? For example. Is it always executing default callback on the Swift side or on the other side? Snapshots will be more helpful : ]

By the way, If you just call methods sending data between Swift and Javascript rather than call registered handlers, that will only trigger default handler since handler is used to deal with 'designated job' and for which you don't designate will be passed through default handler.

Thank you

ksabariraj commented 8 years ago

Hi,

Thanks for the quick update.

I am using Version 7.2.1 (7C1002).

Please find the attachment.

screen shot 2016-07-29 at 10 13 49 am screen shot 2016-07-29 at 10 14 24 am screen shot 2016-07-29 at 10 14 47 am screen shot 2016-07-29 at 10 15 09 am

Thanks.

ksabariraj commented 8 years ago

Hi,

Thanks for your details.

I tried both end. but, still the callback is not firing.

I am receiving message and responseId in data, but, when check if let responseId = swvbMsg["responseId"] as? String { it's failed.

Can you please guide on this?

Note: I tried all function in both javascript and swift. All function failed in the same condition mentioned above.

Thanks, Sabari.

ShawnFoo commented 8 years ago

Hi, Try on these steps to see if program will run to this statement below

return self.messageHandlers[handlerName]
  1. Set up two break points firstly 1
  2. Then, click one of these buttons qq20160804-0

Since calling this method SwiftWebViewBridge.callSwiftHandler("printReceivedParmas", data, null) from the Javascript will send a message carried these infos below. The handlerName, 'printReceivedParmas', is the name of handler registered on Swift side

{
        callbackId = "cb_1_JS_1470057761845";
        data =         {
            age = 6;
            name = "\U5c0f\U660e";
            school = GDUT;
        };
        handlerName = printReceivedParmas;
}

So when Swift run into handleMessagesFromJS method, it will check message sent from JS if it designate a handle to deal with it. If no handlerName or not existed, then return defaultHandler at the end.


A More quickier way, just set up a break point at this line and test if Xcode will break in there 3