gree / unity-webview

zlib License
2.27k stars 687 forks source link

WKWebView #522

Open DevUNakamura opened 4 years ago

DevUNakamura commented 4 years ago

Please give me a chance to ask you. I would like to use WKWebView. I wrote following source code.

void Start()
{
    webViewObject = (new GameObject("WebViewObject")).AddComponent();
    webViewObject.Init((msg)=>{
    if (msg == "clicked") {
    webViewObject.SetVisibility(false);
    }
    },enableWKWebView: true);

    webViewObject.LoadURL(url);
    webViewObject.SetMargins(50,100,50,50);
    webViewObject.SetVisibility(true);
}

But I could not compile correctly with this source code. How can I enable WKWebView? Is there anything my mistake in my source code?

Best Regards.

KojiNakamaru commented 4 years ago

If you see the following error,

error CS0411: The type arguments for method 'GameObject.AddComponent<T>()' cannot be inferred from the usage. Try specifying the type arguments explicitly.

please use AddComponent<WebViewObject>() instead of AddComponent().

DevUNakamura commented 4 years ago

Thank you for giving your response. I checked your suggestion. But I could not solve my issue. I had used "AddComponent() " in my source code. Let me tell you my error message. スクリーンショット 2020-03-26 11 00 39

It can not find "enableWKWebView" parameter. I guess my source code has any mistakes. But I could not find it. My source code is below. スクリーンショット 2020-03-26 11 04 00

I hope you give me any hint to solve this issue. Best Regards.

KojiNakamaru commented 4 years ago

How do you declare webViewObject? It should be declared as below:

    WebViewObject webViewObject;

Therefore the declaration of webViewObject and the definition of Start() method should become:

    WebViewObject webViewObject;

    void Start()
    {
        webViewObject = (new GameObject("WebViewObject")).AddComponent<WebViewObject>();
        webViewObject.Init(
            (msg)=>{
                if (msg == "clicked") {
                    webViewObject.SetVisibility(false);
                }
            },
            enableWKWebView: true);
        webViewObject.LoadURL(url);
        webViewObject.SetMargins(50, 100, 50, 50);
        webViewObject.SetVisibility(true);
    }
DevUNakamura commented 4 years ago

Thank you for giving your quick responding. I tried to solve with using your advice. But unfortunately, I could not solve current problem.

If you can support, could you please review my project. I send the link for my sample project. https://www.dropbox.com/sh/hjpmtn13ousy2ng/AABV1PsPeoetp9du89CzUw3la?dl=1

Anyway, I appreciate with your kindly support. Thanks

KojiNakamaru commented 4 years ago

I checked your app. You seems to import a very old version of this plugin. Please try the latest package: https://github.com/gree/unity-webview/blob/5fcf62fe1365e5097036a8d41c3eea8c426cd592/dist/unity-webview.unitypackage