AFNetworking - reachablity returning always -1

2019-06-05 15:08发布

i use latest AFNetworking sources and the reachablity doesn't work for me, it never fires reachablity 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

Any advice ?

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条回答
不美不萌又怎样
2楼-- · 2019-06-05 15:49

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;
查看更多
登录 后发表回答