AFNetworkReachabilityStatus不会从离线更改为在线

时间:2015-02-11 20:16:13

标签: ios objective-c xcode afnetworking

使用我的iOS模拟器,我在笔记本电脑上打开和关闭WIFI,以测试AFNetworking是否正确检测并切换状态。但是,在下面的代码中,从离线切换到在线后,它总是进入默认情况。为什么会这样?谢谢!

- (void)startReachabilityService
{
    __weak WKNetworkManager *weakSelf = self;
    __weak NSMutableArray *weakRequestQueue = _requestQueue;

    [self setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
    BOOL startExecution = NO;

    switch (status) {
        case AFNetworkReachabilityStatusReachableViaWWAN:
            startExecution = ![weakSelf.currentLogedInUser.isUploadViaWIFI boolValue];
            weakSelf.isConnectionWorking = YES;
            break;
        case AFNetworkReachabilityStatusReachableViaWiFi:
            startExecution = YES;
            weakSelf.isConnectionWorking = YES;
            break;
        case AFNetworkReachabilityStatusNotReachable:
        case AFNetworkReachabilityStatusUnknown:
        default:
            startExecution = NO;
            weakSelf.isConnectionWorking = NO;
            break;
    }

    if (startExecution && weakRequestQueue.count && weakSelf.isQueueRuning == NO) {
        [weakSelf startRequestExecution];
    }
}];

}

1 个答案:

答案 0 :(得分:0)

事实证明,此问题仅适用于iOS模拟器。一旦在实际设备上部署,它似乎检测到交换机正常。