How can I find out that airplane mode is on or off in ios

I would like to turn flight mode on or off by a boolean variable. eg:

Bool airplaneMode = airplanemode;

if(airplaneMode)
{
     NSLoag(@"Airplane mode on");
}
else
{
    NSLoag(@"Airplane mode Off");
}

I don’t want to check network availability or not, I just need to turn airplane mode on or off.

+4
source share
2 answers

AFAIK, there is no built-in api to determine if airplane mode is on. You should check if the appropriate services are available, depending on what you need in your application.

For example, if you need a GPS location, you can check if the GPS location is available, and then handle various cases. The same goes for the network connection and all other services that are disabled when airplane mode is on.

.

+1

API , .

SystemConfiguration , .

Reachability ( tonymillion), -

Reachability* reach = [Reachability reachabilityWithHostname:@"www.google.com"];
reach.reachableBlock = ^(Reachability*reach) {
    // do something to prevent the app to be used
    // NOTE: this block is called on a background thread
    // so if you need to change the UI, do 
    dispatch_async(dispatch_get_main_queue(), ^{
        // UI related stuff
    });
};
reach.unreachableBlock = ^(Reachability*reach) {
    // ok continue using the app
};
[reach startNotifier];
+1

All Articles