gpt4 book ai didi

ios - AFNetworking-可达性始终返回-1

转载 作者:行者123 更新时间:2023-12-01 17:19:32 25 4
gpt4 key购买 nike

我使用最新的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];

最佳答案

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

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

@property (nonatomic, strong) AFHTTPClient *httpClient;

关于ios - AFNetworking-可达性始终返回-1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15452885/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com