可达性在模拟器上工作但不在设备上工作 [英] Reachability working on simulator but not on device

查看:79
本文介绍了可达性在模拟器上工作但不在设备上工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,我正在使用Apple提供的Reachability类。没有互联网连接时,我显示一条警告信息。一切正常,当我在模拟器上测试时,但是当我在iPad上运行它时,没有互联网时不显示警告信息。

In my project I am using Reachability class provided by Apple. When there is no internet connection, I am displaying an alert message. Everything is working fine, when I test it on the simulator, but when am running it on iPad, the alert message is not shown when there is no internet.

我是在iOS 5.0上运行代码。

I am running the code on iOS 5.0.

任何帮助都将不胜感激。

Any help would be appreciated.

编辑:

-(BOOL)isInternetConnectionPresent{

Reachability *objReachability = [Reachability reachabilityForInternetConnection];    
NetworkStatus internetStatus = [objReachability currentReachabilityStatus];

if(internetStatus != NotReachable)
{
    return YES;
}


   return NO;
}

更新:

使用NSLog进行调试。似乎WWAN存在一些问题,即使没有SIM卡也是如此。重启iPad&关闭&再次在Wi Fi上。现在它工作正常。感谢帮助人员。

Used NSLog to debug. Seems there was some problem with WWAN, even when there was no SIM card. Restarted the iPad & switched OFF & ON the Wi Fi again. Now it works fine. Thanks for the help guys.

推荐答案

您必须检查所有 NetworkStatus 并交叉检查设备 Wifi连接状态再次

You have to check all the NetworkStatus and Cross Check the device Wifi Connection status again

示例:

// to check if, wifi connected properly in current device.
- (BOOL)networkCheck {

    Reachability *wifiReach = [Reachability reachabilityForInternetConnection];
    NetworkStatus netStatus = [wifiReach currentReachabilityStatus];

    switch (netStatus)
    {
        case NotReachable:
        {
            NSLog(@"NETWORKCHECK: Not Connected");          
            return NO;
            break;
        }
        case ReachableViaWWAN:
        {
            NSLog(@"NETWORKCHECK: Connected Via WWAN");
            return NO;
            break;
        }
        case ReachableViaWiFi:
        {
            NSLog(@"NETWORKCHECK: Connected Via WiFi");
            return YES;
            break;
        } 
    }
    return false;

}

这篇关于可达性在模拟器上工作但不在设备上工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆