uknownothingsnow / JsBridge

android java and javascript bridge, inspired by wechat webview jsbridge
9.78k stars 2.01k forks source link

h5在dom ready 后callHandler 唤起native registerHandler的方法不成功 #59

Open chenxi0203 opened 8 years ago

chenxi0203 commented 8 years ago

h5在dom ready 后callHandler 唤起native registerHandler的方法不成功 ,当h5加了延时后才才能唤起,是什么原因,若是基于h5点击事件唤起 就没有这个问题

Gavin-YYC commented 8 years ago

试试这个

    if (window.WebViewJavascriptBridge) {
        //do your work here
    } else {
        document.addEventListener(
            'WebViewJavascriptBridgeReady'
            , function() {
                //do your work here
            },
            false
        );
    }
yohanceli commented 8 years ago

@Gavin-YYC 我按照你给的方法,安卓能接收到我传过去的值,但是我接收不到回调的值

        if (window.WebViewJavascriptBridge) {
            window.WebViewJavascriptBridge.callHandler(
                'getDataAndroid',
                {'datakey': value},
                function (localData) {
                    console.log("Java send to JS:"+localData);
                }
            );
        } else {
            document.addEventListener(
                'WebViewJavascriptBridgeReady'
                , function() {
                    window.WebViewJavascriptBridge.callHandler(
                        'getDataAndroid',
                        {'datakey': value},
                        function (localData) {
                            console.log("Java send to JS111111:"+localData);
                        }
                    );
                },
                false
            );
        }
Gavin-YYC commented 8 years ago

你能传值过去,对方能接收,这就意味着连接建立了吧,你没有收到响应,建议先排查下代码问题。 @DHJesus

tangtingyun commented 8 years ago

@DHJesus 我也是你这样的情况 看来好久 你解决了吗?

tangtingyun commented 8 years ago

@DHJesus 哎 是因为没有在js里卖弄调用init方法