Detect if iPhone is in Airplane mode?

后端 未结 2 1896
耶瑟儿~
耶瑟儿~ 2020-12-11 09:54

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, a

2条回答
  •  一整个雨季
    2020-12-11 10:28

    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  _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  delegate; // @synthesize delegate=_delegate;
    
    @end
    

    Then try as below.

    id rp = [[RadiosPreferences alloc] init];
    
    BOOL status = [rp airplaneMode];
    
    return status;
    

提交回复
热议问题