Detect airplane mode on iOS

IosObjective C

Ios Problem Overview


How can I detect if the phone is in airplane mode? (It's not enough to detect there is no internet connection, I have to be able to distinguish these 2 cases)

Ios Solutions


Solution 1 - Ios

Try using SCNetworkReachabilityGetFlags (SystemConfiguration framework). If the flags variable handed back is 0 and the return value is YES, airplane mode is turned on.

Check out Apple's Reachability classes.

Solution 2 - Ios

You can add the SBUsesNetwork boolean flag set to true in your Info.plist to display the popup used in Mail when in Airplane Mode.

Solution 3 - Ios

Since iOS 12 and the Network Framework it's somehow possible to detect if airplane mode is active.

import Network

let monitor = NWPathMonitor()

monitor.pathUpdateHandler = { path in
    if path.availableInterfaces.count == 0 { print("Flight mode") }
    print(path.availableInterfaces)
}

let queue = DispatchQueue.global(qos: .background)
monitor.start(queue: queue)

path.availableInterfaces is returning an array. For example [en0, pdp_ip0]. If no interface is available is probably on flight mode.

WARNING If airplane mode and wifi is active then path.availableInterfaces is not empty, because it's returning [en0]

Solution 4 - Ios

For jailbroken tweaks/apps:

@interface SBTelephonyManager : NSObject
+(id)sharedTelephonyManager;
-(BOOL)isInAirplaneMode;
@end

...

bool isInAirplaneMode = [[%c(SBTelephonyManager) sharedTelephonyManager] isInAirplaneMode];

Solution 5 - Ios

We can not get this information without using private libraries. Here is some code but it will not work when carrier signal is not available.

UIApplication *app = [UIApplication sharedApplication];
NSArray *subviews = [[[app valueForKey:@"statusBar"] valueForKey:@"foregroundView"] subviews];
    
NSString *dataNetworkItemView = nil;
    
for (id subview in subviews) {
    if([subview isKindOfClass:[NSClassFromString(@"UIStatusBarSignalStrengthItemView") class]]) {
            dataNetworkItemView = subview;
            break;
     }
}
double signalStrength = [[dataNetworkItemView valueForKey:@"signalStrengthRaw"] intValue];
 if (signalStrength > 0) {
        NSLog(@"Airplane mode or NO signal");
  }
  else{
        NSLog(@"signal available");
  }

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionCanerView Question on Stackoverflow
Solution 1 - IosFelixView Answer on Stackoverflow
Solution 2 - IosZac WhiteView Answer on Stackoverflow
Solution 3 - IosBilalReffasView Answer on Stackoverflow
Solution 4 - IosClawishView Answer on Stackoverflow
Solution 5 - IosVikash RajputView Answer on Stackoverflow