gree / unity-webview

zlib License
2.3k stars 691 forks source link

iOS white screen on build #589

Open AlohaJava opened 4 years ago

AlohaJava commented 4 years ago

Hello, I am using the latest version of unity-webview. It works good on Android and iOS Simulator, but doesn't work on iOS build ( doesn't load html).

Local path generator

    public string generatePath(string path)
    {
#if (UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX || UNITY_IOS) && !UNITY_EDITOR_WIN
        return Path.Combine("file://" + Application.streamingAssetsPath, path);
#elif UNITY_ANDROID
        return Path.Combine("file:///android_asset/", path);
#else
        return Path.Combine("file://" + Application.streamingAssetsPath, path);
#endif
    }

And using

webViewObject.LoadURL(generatePath("local_www/History/History_XIX.html"));

What can cause this behavior?

AlohaJava commented 4 years ago

Webview doesn't load html? wrong path?

KojiNakamaru commented 4 years ago

I've not found an exact information yet, but I guess at least iOS 13.7 doesn't allow WKWebView access to local files under /private/var/containers/Bundle/Application/.../....app/Data/Raw. This is inconveniet but should make the app more secure. WKWebView can access /var/mobile/Containers/Data/Application/.../Documents/ and copying html files to it - which is done by the sample app - still works.

ReGaSLZR commented 3 years ago

I've not found an exact information yet, but I guess at least iOS 13.7 doesn't allow WKWebView access to local files under /private/var/containers/Bundle/Application/.../....app/Data/Raw. This is inconveniet but should make the app more secure. WKWebView can access /var/mobile/Containers/Data/Application/.../Documents/ and copying html files to it - which is done by the sample app - still works.

So @KojiNakamaru -san , the fix is to not allow WKWebView on iOS? Like: webViewObj.Init(enableWKWebView: false);

I'd just like to ask since I have the same problem where the WebView is just a plain white screen on iOS. It works perfectly fine on Android though.

ReGaSLZR commented 3 years ago

In case the enableWKWebView setting is not the problem, can I ask what is it that causes the WebView to be just a plain white screen in this code snippet? Am I missing a configuration setting somewhere?

            webViewObj.Init(
                cb: elementClickCallback,
                ld: msg => elementClickCallback?.Invoke(PREFIX_WEBVIEW_ON_LOADED + msg),
                started: msg => elementClickCallback?.Invoke(PREFIX_WEBVIEW_ON_STARTED + msg),
                hooked: msg => elementClickCallback?.Invoke(PREFIX_WEBVIEW_ON_HOOKED + msg),
                enableWKWebView: true);

            webViewObj.EvaluateJS(@"Unity.call('ua=' + navigator.userAgent)");
            webViewObj.EvaluateJS(@"
                  document.body.addEventListener(
                    'click',
                    function() {
                      Unity.call('callback', window.location.href);
                    });
                ");

            webViewObj.SetMargins(0, marginTop, 0, marginBottom, true);
            webViewObj.SetVisibility(true);

            if (shouldLoadHTMLBody)
            {
                webViewObj.LoadHTML(html, string.Empty);
            }
            else
            {
                webViewObj.LoadURL(url);
            }

            webViewObj.SetURLPattern("", "", ".*");

Also mentioning here that the iOS model and version my team used for testing (that breeds the white screen display) are: iPhoneSE (OS version: 14.3), iPhone 8 (OS version: 12.1.3), and iPhone XR (OS version: 13).

KojiNakamaru commented 3 years ago

cf. https://github.com/gree/unity-webview/issues/666#issuecomment-812424415