marcuswestin / WebViewJavascriptBridge

An iOS/OSX bridge for sending messages between Obj-C and JavaScript in UIWebViews/WebViews
http://marcuswest.in
MIT License
14.3k stars 2.98k forks source link

How can I get feedback when the js method does not exist? #394

Open ApesTalk opened 4 years ago

ApesTalk commented 4 years ago

When i use WKWebViewJavascriptBridge call js method from iOS like this:

[self.bridge callHandler:@"notExistJsMethod" data:nil responseCallback:^(id responseData) {
        //can not get any response here
 }];

If sometimes the js method does not exist, i can not get any callback to know there is something wrong. If I can get feedback, I can do some default processing.

housenkui commented 4 years ago

had refactor the WebViewJavascriptBridge . If you are in trouble.You can try this. Download Address: https://github.com/housenkui/WebViewJavascriptBridge More light and more simple to use. 10 mins will enough to completed your demand.

housenkui commented 4 years ago

@ApesTalk

Wbqqqq commented 4 years ago

i have same issue @ApesTalk

ThisIszas commented 3 years ago

Search "console.log("WebViewJavascriptBridge: WARNING: no handler for message from ObjC:", message);" inside WebViewJavascriptBridge_JS.m and modify JS code like this:

 if (!handler) {
      console.log("WebViewJavascriptBridge: WARNING: no handler for message from ObjC:", message);
      if (message.callbackId) {
           var callbackResponseId = message.callbackId;
           _doSend({ handlerName:"", responseId:callbackResponseId, responseData:{"error": "jsHandlerNotFound"} });
      }                  
 }

This change require you provide a responseCallback or you cannot receive error callback