I'm doing an apk which when I run it on my cell phone gives me the following error
"Unknow error"
but the strangest thing is that if it works normally when I run it from unity, I used the following code to show me what the error was when I executed it on my cell phone because in unity works perfectly
IEnumerator logIn(WWWForm form)
{
using (UnityWebRequest webRequest = UnityWebRequest.Post("http://localhost:3000/login", form))
{
yield return webRequest.SendWebRequest();
if (webRequest.isNetworkError )
{
Debug.Log(webRequest.error);
advertencia.SetActive(true);
advertencia.GetComponent<Text>().text=webRequest.error+"1";
}
else if (webRequest.isHttpError)
{
advertencia.SetActive(true);
advertencia.SetActive(true);
advertencia.GetComponent<Text>().text = webRequest.error+"2";
}
else
{
SceneManager.LoadScene("Principal");
}
}
}
check if my apk was connected to the internet with the following code that shows a text if it connects to the internet
private void Update()
{
if (Application.internetReachability == NetworkReachability.NotReachable)
{
advertencia.SetActive(true);
Debug.Log("Error. Check internet connection!");
}
}
The code a little more complete:
private Text userText;
private InputField password;
public GameObject advertencia;
private void Start()
{
userText = GameObject.Find("UserInput").GetComponent<Text>();
password = GameObject.Find("PasswordInput").GetComponent<InputField>();
advertencia = GameObject.Find("Advertencia");
advertencia.SetActive(false);
}
//the function with which the corrutina invoked
public void Log()
{
Debug.Log("Usuario : " + userText.text + "\nContraseña : " + password.text);
WWWForm form = new WWWForm();
form.AddField("codigo", userText.text);
form.AddField("contrasena", password.text);
StartCoroutine(logIn(form));
}