Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question iOS web request just hanging...

Discussion in 'Editor & General Support' started by daveMennenoh, Apr 3, 2023.

  1. daveMennenoh

    daveMennenoh

    Joined:
    May 14, 2020
    Posts:
    100
    I need to DL some JSON, but first things first. First, I want to just verify I have a connection on the iPad. This is what I do on Windows:


    Code (CSharp):
    1.  
    2.     IEnumerator IsConnected(Action<bool> action)
    3.     {      
    4.         UnityWebRequest request = UnityWebRequest.Get("http://www.readysetvr.com");
    5.         yield return request.SendWebRequest();
    6.  
    7.         if (request.error != null)
    8.         {
    9.             action(false);
    10.         }
    11.         else
    12.         {
    13.             action(true);
    14.         }
    15.     }
    On iOS (iPad mini) this never finishes. No timeout or anything. Works fine in Editor and on a MS Surface.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,711
    For quite a few years now Apple has required TLS secure transport.

    Try it with an
    https://
    URL and it should work.

    Otherwise there USED to be a "allow non-TLS connections" property you could set in the plist file, but I think those days are over as far as production software goes.

    I know you absolutely will have your app yanked from Google (ask me how I know!) if you state "We send all our data encrypted" and any part of your app is found to fire off a non-encrypted request.

    Pretty sure it does not apply to good old
    Application.OpenURL()
    calls since that just forks the device browser.
     
    daveMennenoh likes this.
  3. daveMennenoh

    daveMennenoh

    Joined:
    May 14, 2020
    Posts:
    100
    Thanks much! Using https:// fixed the problem with it hanging. But now request.error returns with 'Unknown error'. Not too helpful. Works on Windows lol.
     
  4. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,637
    It shouldn't have been hanging, but rather throwing an exception and the rest of the code not executing.
    Your URL does not look correct, it should have a slash at the end.
     
  5. daveMennenoh

    daveMennenoh

    Joined:
    May 14, 2020
    Posts:
    100
    Thanks! Trying it with a slash now, but could it be something with cloud build settings? Kurt mentioned the plist file - do I need to add some post-process script in advanced settings in cloud build? Saw some reference to this for allowing 'unsafe' urls?
     
  6. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,637
    We have a player setting for that. If you enable unsafe HTTP in there, we add the plist item for you.
     
  7. daveMennenoh

    daveMennenoh

    Joined:
    May 14, 2020
    Posts:
    100
    Where is this in player settings? I can't seem to find it.
     
  8. daveMennenoh

    daveMennenoh

    Joined:
    May 14, 2020
    Posts:
    100
    Is it just the Allow 'unsafe' Code check box? I can't find anything else related to unsafe.
     
  9. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,637
    No, that is completely different thing.
    The setting is called "Allow downloads over HTTP".
     
  10. daveMennenoh

    daveMennenoh

    Joined:
    May 14, 2020
    Posts:
    100
    Got a pic or something? 2021.3.2f1 and I see no such thing.
     
  11. daveMennenoh

    daveMennenoh

    Joined:
    May 14, 2020
    Posts:
    100
    So, that is HTTP... I am trying https and I still get "Unknown error". Will this make any diff for https? Also I just don't see that item in settings.

    This is the (very simple) code I am currently trying. Adding a slash at the end makes no diff. Note https as well.


    Code (CSharp):
    1. IEnumerator checkConnection(Action<bool> action)
    2.     {
    3.         UnityWebRequest request = UnityWebRequest.Head("https://www.readysetvr.com");
    4.         request.timeout = 5;
    5.         yield return request.SendWebRequest();
    6.  
    7.         if (request.error != null)
    8.         {
    9.             action(false);
    10.         }
    11.         else
    12.         {
    13.             action(true);
    14.         }
    15.     }
    16.  
     
  12. daveMennenoh

    daveMennenoh

    Joined:
    May 14, 2020
    Posts:
    100
  13. daveMennenoh

    daveMennenoh

    Joined:
    May 14, 2020
    Posts:
    100
  14. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,637
  15. daveMennenoh

    daveMennenoh

    Joined:
    May 14, 2020
    Posts:
    100
    Thanks but.. maybe a little more info would be nice. I mentioned a few times that it's not there - not in 2021.3.2f1 so when did it get added or what can I do in the version I am using? Also I asked - I am using https - will this do anything then?
     
  16. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,637
  17. daveMennenoh

    daveMennenoh

    Joined:
    May 14, 2020
    Posts:
    100
    Yes, I have and it makes no difference and I just did another build to confirm. Still get Unknown Error. Would the 'Allow http' thing even matter for this and any idea why I don't see it?
     
  18. daveMennenoh

    daveMennenoh

    Joined:
    May 14, 2020
    Posts:
    100
    I installed 2021.3.22f1 and that also has no option for 'allow downloads over http'. Can I please got some info on this?
     
  19. daveMennenoh

    daveMennenoh

    Joined:
    May 14, 2020
    Posts:
    100
    So, am on Windows. I switched my build settings to iOS... and then I see that 'allow unsafe http' but it was already checked... So not sure it will do anything, but I saved the project, pushed to git, and am cloud building again.
     
  20. daveMennenoh

    daveMennenoh

    Joined:
    May 14, 2020
    Posts:
    100
    As I suspected, that setting also does nothing - since I am using https. Of course.