我知道如果手机可以访问 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);
即使 3G 和 Wifi 都打开,基本上状态也会返回 1。
这可能吗?
帮助将不胜感激。