gree / unity-webview

zlib License
2.31k stars 695 forks source link

iOS 13 iPhone, if you load multiple urls(count >= 2), you can not close the webview properly, showing a white screen #470

Open EricDDK opened 5 years ago

EricDDK commented 5 years ago

Logs: [Process] kill() returned unexpected error 1 [Process] kill() returned unexpected error 1 [Process] kill() returned unexpected error 1 [Process] kill() returned unexpected error 1 [Process] kill() returned unexpected error 1

KojiNakamaru commented 5 years ago

Thanks, it seems to be due to WebKit's bug: https://stackoverflow.com/questions/58321114/why-i-get-the-console-warning-process-kill-returned-unexpected-error-1-when .

EricDDK commented 5 years ago

Thanks, it seems to be due to WebKit's bug: https://stackoverflow.com/questions/58321114/why-i-get-the-console-warning-process-kill-returned-unexpected-error-1-when .

thanks.

EricDDK commented 5 years ago

Thanks, it seems to be due to WebKit's bug: https://stackoverflow.com/questions/58321114/why-i-get-the-console-warning-process-kill-returned-unexpected-error-1-when .

Hi.. I update iOS 13.2 released version. but it's still happened. Then I use iphone 7plus with iOS 12.(error log disappeared) the webview will show on the screen whether I destroy or set visible. This problem occurs when the same webview loads 2 different urls. And on mac it's okay.

KojiNakamaru commented 5 years ago

The sample app with the following change:

diff --git a/sample/Assets/Scripts/SampleWebView.cs b/sample/Assets/Scripts/SampleWebView.cs
index 1b7596e..c14c4bb 100644
--- a/sample/Assets/Scripts/SampleWebView.cs
+++ b/sample/Assets/Scripts/SampleWebView.cs
@@ -103,33 +103,7 @@ public class SampleWebView : MonoBehaviour
         webViewObject.SetVisibility(true);

 #if !UNITY_WEBPLAYER
-        if (Url.StartsWith("http")) {
-            webViewObject.LoadURL(Url.Replace(" ", "%20"));
-        } else {
-            var exts = new string[]{
-                ".jpg",
-                ".js",
-                ".html"  // should be last
-            };
-            foreach (var ext in exts) {
-                var url = Url.Replace(".html", ext);
-                var src = System.IO.Path.Combine(Application.streamingAssetsPath, url);
-                var dst = System.IO.Path.Combine(Application.persistentDataPath, url);
-                byte[] result = null;
-                if (src.Contains("://")) {  // for Android
-                    var www = new WWW(src);
-                    yield return www;
-                    result = www.bytes;
-                } else {
-                    result = System.IO.File.ReadAllBytes(src);
-                }
-                System.IO.File.WriteAllBytes(dst, result);
-                if (ext == ".html") {
-                    webViewObject.LoadURL("file://" + dst.Replace(" ", "%20"));
-                    break;
-                }
-            }
-        }
+        webViewObject.LoadURL("https://www.google.com");
 #else
         if (Url.StartsWith("http")) {
             webViewObject.LoadURL(Url.Replace(" ", "%20"));
@@ -176,7 +150,7 @@ public class SampleWebView : MonoBehaviour
         GUI.enabled = true;

         if (GUI.Button(new Rect(700, 10, 80, 80), "c")) {
-            Debug.Log(webViewObject.GetCookies(Url));
+            webViewObject.LoadURL("https://www.yahoo.com");
         }
         GUI.enabled = true;
     }

seems to work well for the following steps:

though [Process] kill() returned unexpected error 1 still occurs. My environment is:

Could you please reproduce your issue based on the sample app? Then I could seek any workaround.

EricDDK commented 5 years ago

The sample app with the following change:

diff --git a/sample/Assets/Scripts/SampleWebView.cs b/sample/Assets/Scripts/SampleWebView.cs
index 1b7596e..c14c4bb 100644
--- a/sample/Assets/Scripts/SampleWebView.cs
+++ b/sample/Assets/Scripts/SampleWebView.cs
@@ -103,33 +103,7 @@ public class SampleWebView : MonoBehaviour
         webViewObject.SetVisibility(true);

 #if !UNITY_WEBPLAYER
-        if (Url.StartsWith("http")) {
-            webViewObject.LoadURL(Url.Replace(" ", "%20"));
-        } else {
-            var exts = new string[]{
-                ".jpg",
-                ".js",
-                ".html"  // should be last
-            };
-            foreach (var ext in exts) {
-                var url = Url.Replace(".html", ext);
-                var src = System.IO.Path.Combine(Application.streamingAssetsPath, url);
-                var dst = System.IO.Path.Combine(Application.persistentDataPath, url);
-                byte[] result = null;
-                if (src.Contains("://")) {  // for Android
-                    var www = new WWW(src);
-                    yield return www;
-                    result = www.bytes;
-                } else {
-                    result = System.IO.File.ReadAllBytes(src);
-                }
-                System.IO.File.WriteAllBytes(dst, result);
-                if (ext == ".html") {
-                    webViewObject.LoadURL("file://" + dst.Replace(" ", "%20"));
-                    break;
-                }
-            }
-        }
+        webViewObject.LoadURL("https://www.google.com");
 #else
         if (Url.StartsWith("http")) {
             webViewObject.LoadURL(Url.Replace(" ", "%20"));
@@ -176,7 +150,7 @@ public class SampleWebView : MonoBehaviour
         GUI.enabled = true;

         if (GUI.Button(new Rect(700, 10, 80, 80), "c")) {
-            Debug.Log(webViewObject.GetCookies(Url));
+            webViewObject.LoadURL("https://www.yahoo.com");
         }
         GUI.enabled = true;
     }

seems to work well for the following steps:

though [Process] kill() returned unexpected error 1 still occurs. My environment is:

  • Unity 2019.2.10f1
  • Xcode 11.2
  • iPhone SE/iOS 13.2

Could you please reproduce your issue based on the sample app? Then I could seek any workaround.

I upload a unity sample package. WebBugSample.zip You can import in your sample. start scene, then click url1, then url2. click close, the bug will happen. On mac everything is OK, web object close. But on iphone, it will show on the screen.

Unity 2018.4.9f1 Xcode 11.2 iPhone 7Plus 13.2 latest

KojiNakamaru commented 5 years ago

Your zip contains only Test.unity and Test.cs and cannot be checked instantly. Could you please provide a complete archive that can be run without any addition.

EricDDK commented 5 years ago

Your zip contains only Test.unity and Test.cs and cannot be checked instantly. Could you please provide a complete archive that can be run without any addition.

the complete project. web-bug-sample.zip

KojiNakamaru commented 5 years ago

Okay, I've checked your sample app. It is not a bug. A webview displayed with this plugin is placed over unity's rendering view so image.Setactive(false) doesn't have any effect for the webview. To turn off the webview, OnClickClose() should be the following:

    public void OnClickClose()
    {
        image.SetActive(false);
        web.SetVisibility(false);
    }

(NOTE: the implementation for osx differs from mobile versions. It utilizes a webview off-screen rendered into texture)

EricDDK commented 5 years ago

Okay, I've checked your sample app. It is not a bug. A webview displayed with this plugin is placed over unity's rendering view so image.Setactive(false) doesn't have any effect for the webview. To turn off the webview, OnClickClose() should be the following:

    public void OnClickClose()
    {
        image.SetActive(false);
        web.SetVisibility(false);
    }

(NOTE: the implementation for osx differs from mobile versions. It utilizes a webview off-screen rendered into texture)

Thanks, I test it, it's okay. Then I sync to my project. The error still happen. So I new a sample-2. Please check it again. web-bug-2-sample.zip

KojiNakamaru commented 5 years ago

The code structure differs from the former one. WebViewObject.Init() should not be called multiple times as it creates a WKWebView/UIWebView internally.

EricDDK commented 5 years ago

The code structure differs from the former one. WebViewObject.Init() should not be called multiple times as it creates a WKWebView/UIWebView internally.

thanks. I modify it and everything is okay.