我需要一種方法來檢測如果iPhone處於飛行模式或沒有,我做了一些研究,發現:檢測iPhone是否處於飛行模式?
iphone how to check the Airplane mode?
不工作,我也知道我可以設置SBUsersNetwork顯示警報當在飛行模式下,但它會要求用戶打開WIFI,但我的應用程序需要用戶使用3G和WIFI根本不起作用,所以有沒有任何直接的方式,在CoreTelephony中,我可以做我的工作?
謝謝!
我需要一種方法來檢測如果iPhone處於飛行模式或沒有,我做了一些研究,發現:檢測iPhone是否處於飛行模式?
iphone how to check the Airplane mode?
不工作,我也知道我可以設置SBUsersNetwork顯示警報當在飛行模式下,但它會要求用戶打開WIFI,但我的應用程序需要用戶使用3G和WIFI根本不起作用,所以有沒有任何直接的方式,在CoreTelephony中,我可以做我的工作?
謝謝!
基本上沒有。你不可以做這個。您可以使用Apple的Reachability樣本來檢測網絡連接是否可用。
它不能使用公共API的。
在IOS 5.1中,您可以使用未公開的私有API執行以下操作。這不是蘋果推薦的,不能發送到應用商店。
下面的內容複製粘貼到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
然後如下嘗試。
id rp = [[RadiosPreferences alloc] init];
BOOL status = [rp airplaneMode];
return status;
哪裏是在應用程序RadioPreferences.h文件,這樣我就可以複製並粘貼以上代碼到你,也有需要在項目中訪問RadioPreferences.h添加任何API /框架 –