我使用最新的AFNetworking源并且可达性对我不起作用,它永远不会触发可重复性块,[httpClient networkReachabilityStatus]总是返回-1。 SystemConfiguration / SystemConfiguration.h包含在.pch
中 执行startMonitoringNetworkReachability(在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];
答案 0 :(得分:11)
假设您正在使用ARC,则可能永远不会触发该块,因为只要此方法完成就会释放httpClient
。
要解决此问题,您需要将httpClient
创建为strong
@property
,例如:
@property (nonatomic, strong) AFHTTPClient *httpClient;