gree / unity-webview

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Resolution of Uncaught TypeError: Object [object Object] has no method 'call'

iies opened this issue · comments

Thank you for great library for Unity 3D. But I found one bug that native code can't catch callback from javascript. This problem appears only over Android 4.2.

So I have found on google. This is hint I found : http://stackoverflow.com/questions/14031635/android-4-2-1-webview-and-javascript-interface-breaks

I changed build target to 4.2.2 and modified code like below. (just @JavascriptInterface added)

class WebViewPluginInterface
{
    private String mGameObject;

    public WebViewPluginInterface(final String gameObject)
    {
        mGameObject = gameObject;
    }

    @JavascriptInterface
    public void call(String message)
    {
        UnityPlayer.UnitySendMessage(mGameObject, "CallFromJS", message);
    }
}

In result, this is work fine after added an annotation.

Thank you for sharing the information with us!

This appears to be caused by change in addJavascriptInterface between Android 4.1 (JELLY_BEAN) and 4.2 (JELLY_BEAN_MR1).
Starting from 4.2, only public functions which are annotated with "JavascriptInterface" are accessible from JS, see http://developer.android.com/reference/android/webkit/WebView.html#addJavascriptInterface(java.lang.Object, java.lang.String)
Adding "import android.webkit.JavascriptInterface;" at the top of WebViewPlugin.java and "@JavascriptInterface" immediately before the definition of WebViewPluginInterface.call()
I'll to get around to making a proper pull request with the fix next week (if I don't forget :) )

@splhack you can upload WebViewPlugin.jar fix version for me?
Thanks you

I can't scroll and touch the website in Android.
It's ok in iOS.

The latest version (https://github.com/gree/unity-webview/tree/39d08af311278693abb8c57129dc1b434b062c25) should have no problem. Please try the latest sample/ and dist/unity-webview.unitypackage.