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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

WWW not working on iOS

Discussion in 'iOS and tvOS' started by matbrummitt, Sep 16, 2015.

  1. matbrummitt

    matbrummitt

    Joined:
    Jan 12, 2010
    Posts:
    107
    Hi all,

    My game requires an internet connection, so I have a class that at regular intervals, uses the WWW class to request a page from my website. If there's no error returned then the game has a connection, else there was a problem and there's no connection - an event is triggered for both outcomes, and the UI changes to prompt the user that they need an internet connection to continue using the game.

    In the editor this works great and is very responsive. On mobile though, none of the events are firing.

    Attached is a screenshot from the mobile dev version. Note at the top there's a little debug line with three bits of data (connection:true or false, current game state, extra info:set when either event fires). Note that the extra data segment shows nothing at all - this gets set when either event is triggered, so for some reason it's yielding forever.

    Below is my coroutine code that continuously fires - the Start() method initially sets it going:
    Code (CSharp):
    1.     private IEnumerator CheckConnection ()
    2.     {
    3.         WWW www = new WWW("www.evilegg.co.uk");
    4.        
    5.         yield return www;
    6.        
    7.         if (www.error != null)
    8.         {
    9.             if (HasConnection && OnConnectionFail != null)
    10.                 OnConnectionFail (new System.EventArgs ());
    11.  
    12.             HasConnection = false;
    13.            
    14.             yield return new WaitForSeconds(2);
    15.             StartCoroutine(CheckConnection ());
    16.         }
    17.         else
    18.         {
    19.             if (!HasConnection && OnConnectionSuccess != null)
    20.                 OnConnectionSuccess (new System.EventArgs ());
    21.  
    22.             HasConnection = true;
    23.            
    24.             yield return new WaitForSeconds(2);
    25.             StartCoroutine(CheckConnection ());
    26.         }
    27.        
    28.     }
    Thanks for any advice

    Mat
     
    TheSePo likes this.
  2. pahe

    pahe

    Joined:
    May 10, 2011
    Posts:
    541
  3. matbrummitt

    matbrummitt

    Joined:
    Jan 12, 2010
    Posts:
    107
    Thanks for pointing this out

    Mat
     
  4. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,559
    You may be experiencing a bug in Unity with the WWW class (in case of error, the yield will block forever).

    What version are you on? You can attempt the workaround i suggest in my blog post: http://www.tallior.com/workaround-for-www-yield-bug/

    Also mind you that this is going to be fixed (fixed in 5.1.2p3 and in the next patch for 5.2 i think).
     
  5. matbrummitt

    matbrummitt

    Joined:
    Jan 12, 2010
    Posts:
    107
    Thanks Iiortal,

    I'm on 5.2.0f3. I'll try your suggested wrapper technique and see if that fixes it for me. Thanks for sharing that.

    Mat
     
    liortal likes this.
  6. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,559
    let me know how that worked out :)
     
  7. matbrummitt

    matbrummitt

    Joined:
    Jan 12, 2010
    Posts:
    107
    Hey,

    I just deployed to iOS and i'm getting the exact same problem.

    Cheers

    Mat
     
  8. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,559
    Can u post some more code ?
    How are u starting this coroutune?
     
  9. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,559
    5.2.0p1 is out now, you can test if the issue was resolved for you :)
     
    TheSePo likes this.
  10. jesusluvsyooh

    jesusluvsyooh

    Joined:
    Jan 10, 2012
    Posts:
    377
    I've been getting issues on xcode 7 unity 4.6 with my multiplayer game and www / online features.
    This worked for me : http://stackoverflow.com/a/32631639
    Edit : Added image
     
    Last edited: Sep 22, 2015
    K1kk0z90_Unity likes this.
  11. K1kk0z90_Unity

    K1kk0z90_Unity

    Joined:
    Jun 2, 2013
    Posts:
    90
    Thank you very much! I was facing the same problem and your solution worked perfectly! :)
     
    jesusluvsyooh likes this.
  12. TheSePo

    TheSePo

    Joined:
    May 20, 2015
    Posts:
    3
    That patch fixed it for me.
     
  13. siddharth3322

    siddharth3322

    Joined:
    Nov 29, 2013
    Posts:
    1,042
    I didn't found NSAppTransportSecurity tag in my plist.
    Following is my plist image.

    Screen Shot 2015-10-07 at 12.59.39 pm.png

    Please give me some suggestion.
     
  14. siddharth3322

    siddharth3322

    Joined:
    Nov 29, 2013
    Posts:
    1,042
    Now my problem got solved. I have manually added this tag into my project plist file.

    Screen Shot 2015-10-07 at 1.14.21 pm.png
     
  15. jesusluvsyooh

    jesusluvsyooh

    Joined:
    Jan 10, 2012
    Posts:
    377
    Yep add manually, thats what your supposed to do! ^_^
     
  16. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,559
    You can use the new XCodeAPI to automatically add that as part of a post build step.
     
  17. siddharth3322

    siddharth3322

    Joined:
    Nov 29, 2013
    Posts:
    1,042
    I have added this tag into plist file and every thing works perfectly. Thanks a lot for your help.

    How to get this new XCodeAPI? Please guide me for this resource.
     
  18. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,559
    If you're using Unity 5 or higher, it's included in one of the DLLs that is automatically included with your editor code (under the namespace UnityEditor.iOS.Xcode)
     
  19. siddharth3322

    siddharth3322

    Joined:
    Nov 29, 2013
    Posts:
    1,042
    Thanks for your reply....:)