Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unity webview deal with 404 error #1054

Open
SulemanMox opened this issue Mar 14, 2024 · 8 comments
Open

Unity webview deal with 404 error #1054

SulemanMox opened this issue Mar 14, 2024 · 8 comments

Comments

@SulemanMox
Copy link

Hello I just installed Webview on my Unity game by "KojiNakamaru" which is working great but I am having problem while dealing with 404 error.
I want my App to open Web if the web page is valid, If its missing or 404 error then open the simple app itself.
Any idea how to achieve that?

@KojiNakamaru
Copy link
Member

You can detect it by the httpErr: callback, though the server may return error codes other than 404.

@SulemanMox
Copy link
Author

Koji bro, You are Awesome. Thank you for the direction, I will check it out

@SulemanMox
Copy link
Author

httperr
I have found this line of code, Are you referring to this code?
I want that when my App runs the webview opens my site. If there is a 404 missing error then the webview immediately destroys and The App itself runs.
Can you tell me how can I achieve that?

@KojiNakamaru
Copy link
Member

Yes, in that callback, you can do as the following:

diff --git a/sample/Assets/Scripts/SampleWebView.cs b/sample/Assets/Scripts/SampleWebView.cs
index 14e3428..03ef4e6 100644
--- a/sample/Assets/Scripts/SampleWebView.cs
+++ b/sample/Assets/Scripts/SampleWebView.cs
@@ -52,6 +52,10 @@ public class SampleWebView : MonoBehaviour
                 Debug.Log(string.Format("CallOnHttpError[{0}]", msg));
                 status.text = msg;
                 status.GetComponent<Animation>().Play();
+                if (msg == "404")
+                {
+                    Destroy(webViewObject.gameObject);
+                }
             },
             started: (msg) =>
             {

@SulemanMox
Copy link
Author

httperr

For some reason this line of codes are not working on phone.
I am using - 2022.3.8f1
and this is the link I am trying to insert which returns 404 error - https://navikof.info/

@KojiNakamaru
Copy link
Member

I pushed a modified sample app that can be directly opened and built with 2022.3.14f1 (because a Xcode project exported with 2022.3.8f1 cannot be built with Xcode 15.3) under:

https://github.com/gree/unity-webview/tree/example-for-1054/sample

where 404 test code is found in 767d1c5 . This sample app works okay on OSCAL Pad 8 (Android 11) and iPhone SE 3rd (iOS 17.4).

@SulemanMox
Copy link
Author

I am developing only Android App. I am downloading this sample app which you pushed. And try if thats work.
Thank you for your corporation

@SulemanMox
Copy link
Author

SulemanMox commented Mar 16, 2024

Hello Koji Bro. That sample Project you uploaded worked.
Seems like for some reason 404 error or any error detection works on your sample scene. So I have created new project with your sample project then imported my project as package to your sample project and it worked.
Thank you so much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants