AFNetworking - 可恢复性始终为-1

时间:2013-03-16 18:17:50

标签: ios objective-c 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];

1 个答案:

答案 0 :(得分:11)

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

要解决此问题,您需要将httpClient创建为strong @property,例如:

@property (nonatomic, strong) AFHTTPClient *httpClient;