web view is not working
Nobody has claimed this yet.
- Dominant language
- Objective-C++
- Stars
- 2.7k
- Forks
- 734
- Avg merge
- 11h 39m
- Merged PRs (30d)
- 1
Description
I added the webview plugin to the existing project, but the webview does not open.
did i do something wrong?
unity version 2020.3.10f1
dist-> unity-webview.unitypackage Import
`using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class WebView : MonoBehaviour
{
WebViewObject webViewObject;
public void Event_WebView(string URL, GameObject gameObject)
{
StartCoroutine(webview(URL, gameObject));
}
private IEnumerator webview(string URL, GameObject gameObject)
{
gameObject.SetActive(true);
webViewObject = gameObject.AddComponent<WebViewObject>();
webViewObject.Init(
ld: (msg) =>
{
webViewObject.EvaluateJS(@"Unity.call('ua=' + navigator.userAgent)");
},
enableWKWebView: true);
webViewObject.SetMargins(0, 195, 0, 0); // 화면 여백
webViewObject.SetVisibility(true); // 보일껀지 말껀지
#if !UNITY_WEBPLAYER && !UNITY_WEBGL
if (URL.StartsWith("http"))
{
webViewObject.LoadURL(URL.Replace(" ", "%20"));
Debug.Log("SEUL VALUE CHECK : " + 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 unityWebRequest = UnityWebRequest.Get(src);
yield return unityWebRequest.SendWebRequest();
result = unityWebRequest.downloadHandler.data;
}
else
{
result = System.IO.File.ReadAllBytes(src);
}
System.IO.File.WriteAllBytes(dst, result);
if (ext == ".html")
{
webViewObject.LoadURL("file://" + dst.Replace(" ", "%20"));
break;
}
}
}
#endif
yield break;
}
}
`
`using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TEST : MonoBehaviour
{
public WebView webview;
public GameObject TEMP;
private string URL = "https://www.naver.com/";
// Start is called before the first frame update
void Start()
{
TEMP.SetActive(true);
webview.Event_WebView(URL, TEMP);
}
public void Button_Exit()
{
if (TEMP.GetComponent<WebViewObject>() != null)
{
Destroy(TEMP.GetComponent<WebViewObject>());
TEMP.SetActive(false);
}
}
}
`
I wrote the code as above, After adding 'UNITYWEBVIEW_ANDROID_USES_CLEARTEXT_TRAFFIC' built.
The screen is the same as the default screen,
No problems are logged in logcat.
How do i do?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the issue with Unity 2020.3.10f1 and the imported dist/unity-webview.unitypackage, using the WebView and TEST entry points shown in the report. Inspect WebViewObject initialization and the Android logcat output; the issue is resolved when the supplied webview opens or the missing setup requirement is documented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- unity
- Domain
- mobile-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100