wendux / DSBridge-Android

:earth_americas: A modern cross-platform JavaScript bridge, through which you can invoke each other's functions synchronously or asynchronously between JavaScript and native.
3.73k stars 612 forks source link

Not find method "toAppPage" implementation! please check if the signature or namespace of the method is right #173

Open zhang-yanpeng opened 3 years ago

zhang-yanpeng commented 3 years ago

Not find method "Native本地方法名" implementation! please check if the signature or namespace of the method is right

代码如下: fun initWeb() { showLoading() webView.settings.javaScriptEnabled = true webView.settings.javaScriptCanOpenWindowsAutomatically = true webView.settings.useWideViewPort = true webView.settings.allowContentAccess = true webView.settings.setAppCacheEnabled(false) webView.settings.loadWithOverviewMode = true

    webView.webChromeClient = object : WebChromeClient() 

{

        override fun onProgressChanged(view: WebView?, newProgress: Int) {
            super.onProgressChanged(view, newProgress)
            if (newProgress == 100) {
                hideLoading()
            }
        }
    }

    webView.webViewClient = object : WebViewClient() {
        override fun shouldOverrideUrlLoading(
            view: WebView?,
            request: WebResourceRequest?
        ): Boolean {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                view?.loadUrl(request?.getUrl().toString());
                LogUtil.i("7.0以上 ${request?.getUrl().toString()}")
            } else {
                view?.loadUrl(request.toString());
                LogUtil.i("${request.toString()}")
            }
            return true
        }
    }

// DWebView.setWebContentsDebuggingEnabled(true) webView.addJavascriptObject(AnnieApi(), null) }

public class AnnieApi {

@JavascriptInterface
public String toAppPage(Object name, Object data) {
    LogUtil.INSTANCE.i("toAppPage" + name + data);
    return "" + name;
}

@JavascriptInterface
public void test() {
    LogUtil.INSTANCE.i("test");
}

}

接收的参数都是object的,但还是出现了异常

zhang-yanpeng commented 3 years ago

H5 测试网址 https://study.anniekids.com/a-temporary/app-test/toApp.html
function call(){ dsBridge.call("test"); }

llllllllllx commented 3 years ago

toAppPage只能接受一个参数吧

zhang-yanpeng commented 3 years ago

toAppPage只能接受一个参数吧

是这个问题,好在是已经意识到

rmtic commented 2 years ago

后来解决了吗?