iOS可达性无法捕获连接到WiFi但未登录的情况 [英] iOS Reachability fails to catch the case where connected to WiFi but not logged in

查看:180
本文介绍了iOS可达性无法捕获连接到WiFi但未登录的情况的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天,我公开发布了Beta版应用.我当时在一家旅馆里,尚未获得WiFi的访问代码.在测试可达性时,我注意到它并没有出现应有的失败.它已连接到WiFi,但实际上没有任何连接,因为我没有登录. reachabilityWithHostname 涵盖了此用例.这是我的代码:

Today, I had my Beta-version app out in public. I was at a hotel and had not yet obtained the access code for the WiFi. When testing the reachability, I noticed that it didn't fail as it should have. It was connected to WiFi but nothing was actually reachable because I wasn't logged in. This use-case should be covered by reachabilityWithHostname. Here's my code:

在AppDelegate.h中:

In AppDelegate.h:

@interface AppDelegate : UIResponder <UIApplicationDelegate> {

    Reachability* hostReach;
    Reachability* internetReach;
    Reachability* wifiReach;
}

在AppDelegate.m中:

In AppDelegate.m:

    internetReach = [Reachability reachabilityForInternetConnection];
    [internetReach startNotifier];

    wifiReach = [Reachability reachabilityForLocalWiFi];
    [wifiReach startNotifier];

    hostReach = [Reachability reachabilityWithHostname: @"http://www.google.com"];
    [hostReach connectionRequired];
    [hostReach startNotifier];

在需要连接的模块中:

- (BOOL) isInternetReachable
{
    Reachability *currentReach = [Reachability reachabilityForInternetConnection];
    NetworkStatus netStatus = [currentReach currentReachabilityStatus];


    return (netStatus == ReachableViaWiFi || netStatus == ReachableViaWWAN);
}

有人知道如何解决这种情况吗?

Does anyone know how to cover this circumstance?

推荐答案

我使用可达性来证明网络层.可以确定的时候,我会确定从服务器上加载一个字节的文件.性能还可以.

I use reachability to proof the network layer. When it should be ok than I try to load a one byte file from my server to be really sure. Performance is ok.

BOOL isOnline =  [[[RKClient sharedClient] reachabilityObserver] isReachabilityDetermined] != YES || [[RKClient sharedClient] isNetworkReachable];

    if(isOnline){
        NSData *data = [NSData dataWithContentsOfURL:[[URLManager sharedInstance]availabilityCheckURL]];

        NSString *strTemp = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
        isOnline = [strTemp isEqualToString:@"1"];
    }

这篇关于iOS可达性无法捕获连接到WiFi但未登录的情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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