3

我需要一种方法来检测 iPhone 是否处于飞行模式,我做了一些研究并发现:

iphone如何查看飞行模式?

哪个不起作用,我也知道我可以设置 SBUsersNetwork 以在飞行模式下显示警报,但它会要求用户打开 WIFI,但我的应用需要用户使用 3G,而 WIFI 根本不起作用,所以有什么直前进的方式,在 CoreTelephony 中我可以做我的工作吗?

谢谢!

4

2 回答 2

5

基本上:没有。你不可以做这个。您可以做的是使用 Apple 的Reachability示例来检测网络连接是否可用。

于 2011-11-25T01:38:39.323 回答
4

它不能使用公共 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;
于 2012-05-14T18:16:42.643 回答