1

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

Susanthi
  • 33
  • 1
  • 5
  • Can you post the code you've written so far? It's hard to diagnose something if we can't see any code. – narner Mar 01 '16 at 12:19
  • Reachability *reachability = [Reachability reachabilityForInternetConnection]; [reachability startNotifier]; NetworkStatus status = [reachability currentReachabilityStatus]; if(status == NotReachable) { //No internet } else if (status == ReachableViaWWAN) { //cellular data } else if (status == ReachableViaWiFi) { //Wifi } if both(Wifi and Mobile data) are ON it is executing last block – Susanthi Mar 01 '16 at 12:44

2 Answers2

1

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
     }
Community
  • 1
  • 1
Badal Shah
  • 7,541
  • 2
  • 30
  • 65
  • we can get the network status whether it is enabled or not when we check with individually i.e (WiFi ON & Mobile data OFF and vice versa).what we get the status when both are ON(WiFi ON & Mobile Data ON). It it displaying WiFi status but i want to read the mobile data status also. – Susanthi Mar 01 '16 at 12:42
  • please check note . when you device is connected with wifi then it will left cellular data. – Badal Shah Mar 01 '16 at 12:51
  • when you connect with both then which condition is satisfied ? wifi or cellulardata ? – Badal Shah Mar 01 '16 at 13:06
  • WiFi condition even though if i write cellular data condition first – Susanthi Mar 02 '16 at 07:20
  • yeah i agree that it will left cellular data when WiFi is ON, but i just want to check the mobile data status too. is there any other solution other than reachability class – Susanthi Mar 02 '16 at 07:22
  • but it is not possible. you should think , if mobile is connected through wifi then how it will go to cellular data ? even you write cellular data condition first or wifi condition first. Obviously it will go to the network which is currently connected. There is one trick , i am not sure it will work or not . but if you want to check like, if cellular data is on and user is connected to wifi then enter condition for wifi connect then keep switch on for both and it will go to only wifi with disconnecting cellular data then only go to wifi condition. I am editing the answer try once. not sure . – Badal Shah Mar 02 '16 at 08:06
1

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.

gnasher729
  • 51,477
  • 5
  • 75
  • 98