How do I determine if Mobile Data is on or off (even when WiFi is connected) in iOS?

I have an application that I want to use to get a report on the status of the connection after a certain period of time. Even when I’m connected or connected to a Wi-Fi network, I would like to know if data access via the cellular network is turned on. This means that if after checking I can gracefully disconnect from the Wi-Fi network, knowing that there is an available cellular connection to which the device will be connected.

Existing Accessibility methods will provide me with information about cellular availability only when you are connected to it, and there is not much information about receiving this data before actually connecting to the interface.

Look for a similar solution available in android as described in this link .

EXPLANATIONS

I do NOT see if my device has cellular capabilities. I am trying to establish whether the user was enabled / disabled access to data via the mobile network, and would like to know this information even if I am connected to Wi-Fi. The user can enable or disable this by selecting Settings.

+6
source share
4 answers

api, , . CTCellularData cellDataRestrictionDidUpdateNotifier limitedState, , . iOS . , , .

+3

https://github.com/ashleymills/Reachability.swift , WWAN

var isReachableViaWWAN: Bool {
    // Check we're not on the simulator, we're REACHABLE and check we're on WWAN
    return isRunningOnDevice && isReachableFlagSet && isOnWWANFlagSet
}
0

, , : , () :

  • , , WiFi , - .
  • .
  • , Wi-Fi ( .).
  • , ™

( , , , ).

0

u can know all the scenarios:

 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNetworkChange:) name:kReachabilityChangedNotification object:nil];
        Reachability *reachablity=[Reachability reachabilityWithHostName:@"google.com"];

        [reachablity startNotifier];

        //    reachablity = [Reachability reachabilityForInternetConnection];

        NetworkStatus remoteHostStatus = [reachablity currentReachabilityStatus];
        if(remoteHostStatus == NotReachable) {
            NSLog(@"network not available ");


        }
        else if (remoteHostStatus == ReachableViaWiFi) {
            NSLog(@"connect with wifi");


        }
        else if (remoteHostStatus == ReachableViaWWAN) {
            NSLog(@"Cellulor network ");


        }
        return netwrokCheck;
-one
source

Source: https://habr.com/ru/post/1015957/


All Articles