Objective c 可达性飞机模式(3G)与Wifi

Objective c 可达性飞机模式(3G)与Wifi,objective-c,ios,3g,reachability,Objective C,Ios,3g,Reachability,我知道,如果手机可以接入Wifi或3G网络,则可达性代码将提供 但是,如果手机已打开3G和Wifi,则可达性代码默认表示手机已打开Wifi,并且我无法检测3G网络是否已启用(飞机模式打开或关闭) 我需要特别了解Wifi同时开启时3G模式是开启还是关闭 代码如下: Reachability *reachability = [Reachability reachabilityForInternetConnection]; [reachability startNotifier]; NetworkS

我知道,如果手机可以接入Wifi或3G网络,则可达性代码将提供

但是,如果手机已打开3G和Wifi,则可达性代码默认表示手机已打开Wifi,并且我无法检测3G网络是否已启用(飞机模式打开或关闭)

我需要特别了解Wifi同时开启时3G模式是开启还是关闭

代码如下:

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都已开启

这可能吗


非常感谢您的帮助。

更新:目前似乎不可能。但是,如果有帮助,您可以尝试以下代码以防万一

代码1:只是一个想法。我没试过这个

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 

目前,在iPhone上,按照苹果的指导方针,如果不使用他们的专用API,就无法做到这一点。

如果手机可以同时访问3G和Wi-Fi,它将始终连接到Wi-Fi网络,而不是选择3G,因此检测这一事实可能没有意义。我知道你在说什么,但是,在我的情况下,不幸的是,它必须检测我正在开发的应用程序是否启用了3G。请检查此链接,它可能对您有用,所以我尝试了此链接,但canOpenURL没有改变任何东西。它仍然认为3G在飞机模式下也是可用的。然后我还尝试了openURL:[NSURL URLWithString:@”tel://1234567“]但这一次,它会显示一条消息,说您必须禁用飞行模式才能打电话。就像在飞机模式下打电话时收到的正常消息一样,请参见,,非常感谢您的RadiosPreferences编辑和所有其他帮助,尽管RadiosPreferences不起作用,但它始终返回状态为NO(false)。我还发现:苹果不允许开发者检查这个简单的标志是没有任何意义的。而且,这个应用程序在完成后需要放在AppStore上,所以这也没有帮助
id rp = [[RadiosPreferences alloc] init];
BOOL status = [rp airplaneMode];
return status;