AFNetworking-可达性始终返回-1 [英] AFNetworking - reachability returning always -1

查看:94
本文介绍了AFNetworking-可达性始终返回-1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用最新的AFNetworking来源,可访问性对我而言不起作用,它从不触发可访问性块,并且 [httpClient networkReachabilityStatus] 始终返回-1。 .pch

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已执行(在AFHTTPClient中)。

startMonitoringNetworkReachability is executed (in AFHTTPClient).

iPhone 4已包含SystemConfiguration / SystemConfiguration.h。 ,iOS 6.1

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];


推荐答案

假设您正在使用ARC,则该块可能永远不会被解雇,因为此方法完成后,您的 httpClient 即将被释放。

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.

要解决此问题,您需要创建 httpClient 作为 strong @property

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

@property (nonatomic, strong) AFHTTPClient *httpClient;

这篇关于AFNetworking-可达性始终返回-1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆