AFNetworking - reachability returning always -1

梦想与她 提交于 2019-12-23 02:49:32

问题


I use latest AFNetworking sources and the reachability doesn't work for me, it never fires reachability block and the [httpClient networkReachabilityStatus] always returns -1. SystemConfiguration/SystemConfiguration.h is included in .pch

startMonitoringNetworkReachability is executed (in AFHTTPClient).

iPhone 4, iOS 6.1

AFHTTPClient *httpClient = [AFHTTPClient clientWithBaseURL:[NSURL URLWithString:URL]];

[httpClient setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {

    NSLog(@"Internet status changed");
    NSLog(@"%d", status);
}];

NSMutableURLRequest *request = [httpClient requestWithMethod:@"POST" path:method parameters:post];

NSLog(@"Network reach %d",[httpClient networkReachabilityStatus]);

AFJSONRequestOperation *operation = [self getOperationWithMethod:method withRequest:request andCallback:callback];

[operation start];

回答1:


Assuming you're using ARC the block is probably never being fired because your httpClient is being released as soon as this method is finished.

To fix this you would need to create your httpClient as a strong @property such as:

@property (nonatomic, strong) AFHTTPClient *httpClient;


来源:https://stackoverflow.com/questions/15452885/afnetworking-reachability-returning-always-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!