-1

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?

ChrisF
  • 127,439
  • 29
  • 243
  • 315
Bharat Jagtap
  • 1,689
  • 2
  • 22
  • 35

2 Answers2

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");
  }
Vikash Rajput
  • 423
  • 3
  • 20
-1
NSDictionary* infoDict = [[NSBundle mainBundle] infoDictionary];
[infoDict objectForKey:@"SBUsesNetwork"];

Hope this helps.

grc
  • 20,175
  • 4
  • 37
  • 63
Nana
  • 1