I just want to know programmatically if the iPhone is in airplane mode. I know We have to add SBUsesNetwork boolean flag in the info plist but that dose not serve my purpose. Actually I am using reachabillity class to identify the internet availability so when my app when starts in airplane mode gives two alert one from my code and other from SBUsesNetwork flag . I juts want to display either of these two alerts. So I want to programmatically know if the phone is in airplane mode?
Asked
Active
Viewed 2,688 times
2 Answers
0
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");
}
![](../../users/profiles/4951887.webp)
Vikash Rajput
- 423
- 3
- 20