bil*_*y91 4 objective-c reachability ios7 afnetworking-2
我在使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;
}
Run Code Online (Sandbox Code Playgroud)
我已经在我的.pch中导入了SystemConfiguration/SystemConfiguration.h,正如文档所述.每当我要求状态时,我得到值-1.
有帮助吗?
更新:
我在这里添加我的PodFile:
pod 'AFNetworking' ,'~> 2.0.0'
pod 'AFNetworking/Reachability' ,'~> 2.0.0'
Run Code Online (Sandbox Code Playgroud)
bil*_*y91 25
我需要启动可达性监视器.
[self.manager.reachabilityManager startMonitoring];
Run Code Online (Sandbox Code Playgroud)
我偶然发现它,文档应该在我看来说明这一点.
| 归档时间: |
|
| 查看次数: |
7268 次 |
| 最近记录: |