【问题标题】:Detect if iPhone is in Airplane mode?检测 iPhone 是否处于飞行模式?
【发布时间】:2011-11-25 01:34:26
【问题描述】:

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

iphone how to check the Airplane mode?

这不起作用,我也知道我可以将 SBUsersNetwork 设置为在飞行模式下显示警报,但它会要求用户打开 WIFI,但我的应用需要用户使用 3G,而 WIFI 根本不起作用,所以是在 CoreTelephony 中有什么直接的方法可以让我完成我的工作吗?

谢谢!

【问题讨论】:

    标签: iphone core-telephony airplane


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      使用公共 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 文件在哪里,以便我可以将上面的代码复制并粘贴到该文件中,是否需要在项目中添加任何 api/framework 才能访问 RadioPreferences.h
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-24
      • 2012-07-30
      • 1970-01-01
      • 2018-05-22
      • 2016-08-29
      • 2011-12-03
      相关资源
      最近更新 更多