• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by OSG · Apr 08, 2014 at 11:04 AM · ioswwwinternet

Internet reachability on iOS

Hi all. I have some problems with internet connection on iOS device. I have Android build of my game which is working perfect. I posting high scores to my web-server via WWW class. Everything works. But when I testing my app on iPhone there is some problem with posting and getting high scores. To check internet reachability I use Application.internetReachability and I have simple function which tries to get response from the server and if WWW class returns right answer from the server I set my special bool value to TRUE. So with turned on Wi-Fi on the iPhone app can't get any response from server, and it seems that server doesn't get any query from the app.

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image OSG · Apr 08, 2014 at 01:54 PM 0
Share

Checked Application.internetReachability value on the iPhone and it shows "ReachableViaLocalAreaNetwork", but devise connected only to Wi-Fi. Does anybody had the same problem?

avatar image Slobdell · Apr 08, 2014 at 08:21 PM 1
Share

I think that means it's connected to wifi but not the internet. You sure your router has Internet access?

avatar image OSG · Apr 09, 2014 at 06:02 AM 0
Share

Yes I have Internet access. I tested in app purchases and it works, I tested ads then and it works, too. Well, I read some articles about WWW class and as I understand this class works good on iOS. And as I said all my functions for leader board work on Android device. Both Android and iOS devices connected to same wi-fi router.

4 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by OSG · Apr 10, 2014 at 06:04 AM

Finally I found source of the problem. Firstly I added String.IsNullOrEmpty(www.error), not sure that it is necessary. And the main problem was with info.plist file. There is a string "Application uses Wi-Fi" and it's value is YES. I thought that it's enough for wi-fi availability on iOS device and I was wrong.

So to use Wi-Fi for WWW class we need to add "wifi" item to "Required device capabilities". I don't know why it was not added automatically. Hope this will help somebody. And big thanks for helping to @flamy

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image flamy · Apr 29, 2014 at 09:28 AM 0
Share

weird it seems to happen in android too!!

avatar image
2

Answer by flamy · Apr 09, 2014 at 06:31 AM

 public class CheckInternet : MonoBehaviour {

     public static CheckInternet instance;
     const float CheckTimer = 5f;
 
     public bool isconnectedToInternet = false;

     void Awake()
     {
        
           instance = this;
     }

     void Start () {

         InvokeRepeating("PingService",0,CheckTimer);
     }
 
     void PingService()
     {
         StartCoroutine(PingGOOGLE());
     }
 
     IEnumerator PingGOOGLE()
     {
         WWW www = new WWW("www.google.com");
 
         yield return www;
 
         if(www.error == "" || www.error == null)
         {
             isconnectedToInternet = true;
         }
         else
         {
             isconnectedToInternet = false;
         }
     }
 
 }


this continously pings google every "checkTimer" seconds and isConnectedToInternet gives you the status.

Attach the file to a gameobejct and when you want to check connection, use CheckInternet.instance.isconnectedToInternet == true

alternatively you can use Ping class which is useful for the same purpose especially if u have your own server and check for its rechability

Comment
Add comment · Show 8 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image OSG · Apr 09, 2014 at 10:59 AM 0
Share

I added your code and on iOS devices (tested on 2 iPhones) it shows that there is no connection. I have no idea why I can't reach the Internet via WWW class on iOS. But anyway, thank you for answer.

avatar image flamy · Apr 09, 2014 at 11:08 AM 0
Share

does it reach internet on browser??

should be the problem there!

avatar image OSG · Apr 09, 2014 at 11:43 AM 0
Share

Opened browser and successfully opened google.com page, after that opened game and isconnectedToInternet variable is False :( It is very strange that it works as it should on $$anonymous$$acBook, on PC with win 8.1 and Android phone but don't work on iOS. In Unity last updates there are some fixes with iOS and WWW class, so I updated Unity to the latest 4.3.4 version but it didn't help me.

avatar image flamy · Apr 09, 2014 at 11:49 AM 0
Share

im actually not sure if this would solve the problem, can you just try to switch on "Requires Persistent Wifi" in ios build settings -> other settings tab

avatar image OSG · Apr 09, 2014 at 12:28 PM 0
Share

I checked this setting before :) It os turned on in plist.info and when game is installed on iPhone there is internet permission in settings and it is turned on too. It looks like I missing just one little peace of this puzzle, but I can't find it.

Show more comments
avatar image
0

Answer by tonic · Jun 27, 2014 at 02:13 PM

To truly know you're online, you need to implement "captive portal detection", to know if you're e.g. hitting a public WiFi login page. So just checking Application.internetReachability or doing a Ping to some address doesn't guarantee you can successfully make connections or make WWW requests.

I have made an easy asset which keeps you up-to-date whether you have verified internet access (WWW requests can be done). Works with Desktop, Mobile and Webplayer platforms (need to self-host a file in originating server for Webplayer). More info here: http://j.mp/IRVUN

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by grujicbr · Aug 19, 2014 at 06:39 PM

Hi,

I have released a event based plugin for ios that lets you do exactly this without having to do it manually. It is very easy to use and works on all ios devices. Android version is on works as well

https://www.assetstore.unity3d.com/en/#!/content/19869

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

26 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

www 404 error only on iOS 1 Answer

WWW.h crash in store build 5 Answers

Detect if device is connected to Wifi 3 Answers

Assetbundle memory leaks 0 Answers

How to upload/download video from/to mobile 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges