我正在使用 AFNetworking 3.0 在我的应用程序中执行 Web 请求。有没有办法在互联网恢复时自动重试请求?
这是请求代码:
@try {
NSString *urlMuniByGov = [NSString stringWithFormat:@"%@/%@", URL_MUNICIPALITES, selectedGov.govID];
NSURL *url = [NSURL URLWithString:urlMuniByGov];
AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc] init];
manager.responseSerializer = [AFJSONResponseSerializer serializer];
manager.securityPolicy.allowInvalidCertificates = YES;
[manager GET:url.absoluteString
parameters:nil
progress:nil
success:^(NSURLSessionDataTask * task, id responseObject) {
NSArray *muniNSArray = [responseObject objectForKey:@"municipalites"];
if ([muniNSArray isKindOfClass:[NSArray class]]){
for (NSDictionary *dictionary in muniNSArray) {
Municipality *munModel = [Municipality new] ;
munModel.munID = [dictionary objectForKey:@"id"];
munModel.munNameAr = [[dictionary objectForKey:@"nom"] objectForKey:@"ar"];
munModel.munNameFr = [[dictionary objectForKey:@"nom"] objectForKey:@"fr"];
[self.munsArray addObject:munModel];
[self.munsString addObject:munModel.munNameAr];
}
}
[municipalityText setItemList:[NSArray arrayWithArray:self.munsString]];
} failure:^(NSURLSessionDataTask * task, NSError * error) {
NSLog(@"Error: %@", error);
}];
}
@catch (NSException *exception) {
NSLog(@"Exception: %@", exception);
}