可达性飞机模式(3G)与WiFi

我知道如果手机可以访问Wifi或3Gnetworking,可达码将会提供。

但是,如果手机有3G和Wifi,则可达性代码默认为说手机已启用Wifi,并且无法检测3Gnetworking是否启用(飞行模式开启或closures)。

我需要找出具体的3G模式是否打开或closures的Wifi也打开。

这里是代码:

Reachability *reachability = [Reachability reachabilityForInternetConnection]; [reachability startNotifier]; NetworkStatus status = [reachability currentReachabilityStatus]; NSLog(@"status: %u", status); if(status == NotReachable) //status = 0 { //No internet NSLog(@"nothing is reachable"); } if (status == ReachableViaWiFi) //status = 1 { //WiFi NSLog(@"Wifi is available"); } if (status == ReachableViaWWAN) //status = 2 { //3G NSLog(@"3G is available"); } NSLog(@"%@", s); 

基本上状态是返回1,即使3G和Wifi一样。

这可能吗?

帮助将不胜感激。

更新:好像现在不可能。 但是,你可以尝试下面的代码,以防万一,如果有帮助。

Code1:只是一个想法。 没有试过这个。

 if (status == ReachableViaWiFi) //status = 1 { if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"tel://"]]) { NSLog(@"Wifi and 3G are available"); } else { NSLog(@"Wifi is available, but 3G is not available"); } } 

代码2:

对于内部应用程序,您可以使用此处提到的方法,

注意:这使用私有API,所以如果您在appstore应用程序中使用它,您的应用程序将被拒绝。

将以下内容复制粘贴到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; 

目前没有办法遵循苹果的指导方针,而不使用他们的私人API在iPhone上做到这一点。