Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

UnityWebRequest never returning from yield return www.Get() on Android and iOS when backend is IL2CP

Discussion in 'Connected Games' started by Callumnibus, Jun 20, 2019.

  1. Callumnibus

    Callumnibus

    Joined:
    Jul 23, 2015
    Posts:
    3
    I'm fairly new to networking so there's chance (hopefully) this'll be an easy question. I've set up an apache server that's reached via an HTTP request e.g. http://myserver.ddns.net. This method below reaches the yield statement but never proceeds. What's weird is that it works in the editor and if I deploy to android using the Mono backend, however doesn't work when built with IL2CPP on either android or iOS (unsure about iOS using Mono). My instincts are using http isn't allowed (need https?) and / or I should use a different framework like WWWRequest or HttpRequest instead?

    Any thoughts would be greatly appreciated as this is app breaking at the moment! Thanks

    Code (CSharp):
    1.  
    2. private IEnumerator GetEventsRoutine(Action<bool, StoredEventData> callback, bool forceGet)
    3. {
    4. LogUtil.Write("Trying to get new event data");
    5.  
    6. // get last update time
    7.  
    8. DateTime lastUpdated;
    9.  
    10. if (!forceGet)
    11. {
    12. string lastUpdatedString = PlayerPrefs.GetString(m_lastUpdatePrefsKeys, new DateTime(0).ToString());
    13.  
    14. lastUpdated = DateTime.Parse(lastUpdatedString);
    15. }
    16. else
    17. {
    18. // this will make the server skip the update test and return events
    19. lastUpdated = new DateTime(0);
    20. }
    21.  
    22. WWWForm form = new WWWForm();
    23. form.AddField("date", lastUpdated.ConvertToUnixTime().ToString());
    24.  
    25. UnityWebRequest www = UnityWebRequest.Get(m_url);
    26.  
    27. yield return www.SendWebRequest();
    28.  
    29. if (www.isNetworkError || www.isHttpError)
    30. {
    31. callback?.Invoke(false, default);
    32. LogUtil.WriteError(www.error);
    33. yield break;
    34. }
    35.  
    36. LogUtil.Write("Got new event data");
    37. }
    38.  
     
  2. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    2,212
    The code looks fine except for the WWWForm, that is created and not used.
    HTTP works on iOS, newest Android versions require HTTPS, however you can still enable HTTP in the manifest (search the Android forum for exact setting).
    Are you sure it gets stuck on yield return and not some exception is thrown? Check the log. Mono/IL2CPP should not make a difference in behavior in general.