How can i know airplane mode on or off in ios

5.1k views Asked by At

i would like to check airplane mode on or off on boolean variable. for example :

Bool airplaneMode = airplanemode;

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

i don't want to check Network is available or not i need only to check airplane mode on or off.

2

There are 2 answers

0
eschanet On BEST ANSWER

AFAIK, there is no built-in api to determine if Airplane mode is on. You have to check if the respective services are available, depending on what you need in your app.

For example, if you need a GPS location, you could check if a GPS location is available and then handle your different cases. Same for a network connection and all the other services that are disabled when airplane mode is on.

Rechability is one example for checking network connection.

0
AudioBubble On

There's currently no public API for direct checking whether the airplane mode is on.

The closest solution would be to use the SystemConfiguration framework and monitor whether the device can connect to the network.

Using the Reachability class (by tonymillion) you can do something like

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];