WWW not working on iOS

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:

    private IEnumerator CheckConnection ()
    {
        WWW www = new WWW("www.evilegg.co.uk");
       
        yield return www;
       
        if (www.error != null)
        {
            if (HasConnection && OnConnectionFail != null)
                OnConnectionFail (new System.EventArgs ());

            HasConnection = false;
           
            yield return new WaitForSeconds(2);
            StartCoroutine(CheckConnection ());
        }
        else
        {
            if (!HasConnection && OnConnectionSuccess != null)
                OnConnectionSuccess (new System.EventArgs ());

            HasConnection = true;
           
            yield return new WaitForSeconds(2);
            StartCoroutine(CheckConnection ());
        }
       
    }

Thanks for any advice

Mat

1 Like

You should post your question in the iOS subforum.

Check here: A workaround for the "yield return www" hang on iOS - Unity Engine - Unity Discussions

Thanks for pointing this out

Mat

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).

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

1 Like

let me know how that worked out :slight_smile:

Hey,

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

Cheers

Mat

Can u post some more code ?
How are u starting this coroutune?

5.2.0p1 is out now, you can test if the issue was resolved for you :slight_smile:

1 Like

I’ve been getting issues on xcode 7 unity 4.6 with my multiplayer game and www / online features.
This worked for me : ios - App Transport Security Xcode 7 beta 6 - Stack Overflow

Edit : Added image

1 Like

Thank you very much! I was facing the same problem and your solution worked perfectly! :slight_smile:

1 Like

That patch fixed it for me.

I didn’t found NSAppTransportSecurity tag in my plist.
Following is my plist image.

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

Please give me some suggestion.

Now my problem got solved. I have manually added this tag into my project plist file.

Yep add manually, thats what your supposed to do! :slight_smile:

You can use the new XCodeAPI to automatically add that as part of a post build step.

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.

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)

Thanks for your reply…:slight_smile: