我的以下代码运行良好,但我需要对其进行更多控制,尤其需要开始使用 0.9 中的可达性代码。
NSString *urlString = [NSString stringWithFormat:@"http://example.com/API/api.php"];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
_self.mainDictionary = [JSON valueForKeyPath:@"elements"];
[_self parseLiveData];
} failure:^(NSURLRequest *request , NSURLResponse *response , NSError *error , id JSON){
//NSLog(@"Failed: %@",[error localizedDescription]);
}];
if (operation !=nil && ([self.sharedQueue operationCount] == 0)) {
[self.sharedQueue addOperation:operation];
}
我正在努力研究如何将相同的代码转换为使用 AFHTTPClient,以便我可以利用“setReachabilityStatusChangeBlock”。