Susanthi
Susanthi

Reputation: 33

How to get Mobile data status in iPhone when WiFi is ON

Currently i am working on an iPhone Application which needs to display the mobile data status(ON/OFF). For network check im using Reachability class but it is giving me correct result when any one of the networks are enable i.e WiFi/Mobile Data, but if both are enable it is giving Wifi status, but my requirement is i just need to mobile data status also. It would be great if anyone suggest me solution.

Thankq

Upvotes: 1

Views: 1119

Answers (2)

gnasher729
gnasher729

Reputation: 52538

Sadly, there seems to be no way to check that mobile data is turned on when WiFi is turned on. You can detect whether there is a WiFi connection, whether there is no WiFi connection but a mobile data connection, or whether there is no connection at all. But if there is a WiFi connection, there seems to be no way to detect whether there is a data connection as well.

Using the telephony classes, you can detect whether the device has a SIM card, and you can detect whether mobile data has been disabled in Settings for your application. You can not detect as far as I know whether mobile data is enabled for the whole device.

You can also not distinguish between Wifi turned off, WiFi turned on but no network nearby or selected, and Airplane mode turned on.

Upvotes: 1

Badal Shah
Badal Shah

Reputation: 7602

Set some logic , like check , if network is connected to Wifi or Cellular-data , and then set your code in cellular data.

Reachability *reachability = [Reachability reachabilityForInternetConnection];
[reachability startNotifier];

NetworkStatus status = [reachability currentReachabilityStatus];
if(status == NotReachable) 
{
    //No internet
}
else if (status == ReachableViaWiFi)
{
    //WiFi
}
else if (status == ReachableViaWWAN) 
{
    //3G // Set your code here for cellular data
}

Find more detail on ios-detect-3g-or-wifi set according to your requirement.

Note :- I think when your iPhone is connected with wifi then it lefts cellular data automatically and if disconnect wifi then again connected with cellular data

Edit :- I am not sure but try this ,

if(status == NotReachable) 
    {
        //No internet
    }
   else if (status == ReachableViaWWAN) 
    {
        //3G // Set your code here for cellular data
       if (status == ReachableViaWiFi)
      {
        //WiFi // Keep Wifi and cellulardata both on.
      }
    }
    else if (status == ReachableViaWiFi)
    {
        //WiFi
    }


     else if (status == ReachableViaWWAN) 
    {
      // keep status only cellularadat on
     }

Upvotes: 1

Related Questions