Detect if iPhone is in Airplane mode?
Asked Answered
P

2

3

I need a way to detect if the iPhone is in Airplane Mode or not, I did some research and found:

iphone how to check the Airplane mode?

Which does not work, also I know I can set SBUsersNetwork to show an alert when in airplane mode, but it will ask user to switch on WIFI but my app need user to use 3G and WIFI simply does not work, so is there any straight forward way, in CoreTelephony that I can do my job?

Thanks!

Polio answered 25/11, 2011 at 1:34 Comment(0)
C
5

Basically: no. You cannot do this. What you can do is use the Reachability samples from Apple to detect if a network connection is available.

Chromatogram answered 25/11, 2011 at 1:38 Comment(0)
S
4

It cannot be done using public API's.

In IOS 5.1, you can do as follows using undocumented private API's. This is not recommended by apple and cannot be shipped to app store.

Copy paste the below contents into RadioPreferences.h


@protocol RadiosPreferencesDelegate
-(void)airplaneModeChanged;
@end


@interface RadiosPreferences : NSObject
{
    struct __SCPreferences *_prefs;
    int _applySkipCount;
    id <RadiosPreferencesDelegate> _delegate;
    BOOL _isCachedAirplaneModeValid;
    BOOL _cachedAirplaneMode;
    BOOL notifyForExternalChangeOnly;
}

- (id)init;
- (void)dealloc;
@property(nonatomic) BOOL airplaneMode;
- (void)refresh;
- (void)initializeSCPrefs:(id)arg1;
- (void)notifyTarget:(unsigned int)arg1;
- (void)synchronize;
- (void *)getValueForKey:(id)arg1;
- (void)setValue:(void *)arg1 forKey:(id)arg2;
@property(nonatomic) BOOL notifyForExternalChangeOnly; // @synthesize notifyForExternalChangeOnly;
@property(nonatomic) id <RadiosPreferencesDelegate> delegate; // @synthesize delegate=_delegate;

@end

Then try as below.

id rp = [[RadiosPreferences alloc] init];

BOOL status = [rp airplaneMode];

return status;
Sarette answered 14/5, 2012 at 18:16 Comment(1)
Where is RadioPreferences.h file in the application, so that i can copy and paste above code into that, also is there any api/framework needed to be added in the project to access the RadioPreferences.hAnthurium

© 2022 - 2024 — McMap. All rights reserved.