AFNetworking - 可恢复性始终为-1

Pio*_*ion 1 objective-c ios afnetworking

我使用最新的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];
Run Code Online (Sandbox Code Playgroud)

Kei*_*ley 11

假设您正在使用ARC,则块可能永远不会被触发,因为httpClient一旦此方法完成,您就会被释放.

要解决此问题,您需要创建httpClient一个strong @property如下:

@property (nonatomic, strong) AFHTTPClient *httpClient;
Run Code Online (Sandbox Code Playgroud)