我在使 AFNetworking Reachability 模块正常工作时遇到一些问题。我已经使用 ReachabilityStatusChangeBlock 设置了 AFHTTPRequestOperationManager 但它从未被调用。
self.manager = [[AFHTTPRequestOperationManager alloc] initWithBaseURL:[NSURL URLWithString:@"http://192.168.1.2:3000"]];
self.manager.responseSerializer = [AFJSONResponseSerializer serializer];
NSOperationQueue *operationQueue = self.manager.operationQueue;
[self.manager.reachabilityManager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
switch (status) {
case AFNetworkReachabilityStatusNotReachable:
// we need to notify a delegete when internet conexion is lost.
// [delegate internetConexionLost];
NSLog(@"No Internet Conexion");
break;
case AFNetworkReachabilityStatusReachableViaWiFi:
NSLog(@"WIFI");
break;
case AFNetworkReachabilityStatusReachableViaWWAN:
NSLog(@"3G");
break;
default:
NSLog(@"Unkown network status");
[operationQueue setSuspended:YES];
break;
}
正如文档所述,我已在 .pch 中导入 SystemConfiguration/SystemConfiguration.h。每次我询问状态时,我都会得到值-1。
有什么帮助吗?
UPDATE:
我在这里添加我的 PodFile:
pod 'AFNetworking' ,'~> 2.0.0'
pod 'AFNetworking/Reachability' ,'~> 2.0.0'
我需要启动可达性监视器。
[self.manager.reachabilityManager startMonitoring];
我偶然发现它,我认为文档应该说明这一点。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)