我试图使用异步操作请求,但在某些时候操作请求由于请求超时失败。如何组成我的块,以便在所有操作完成失败或完成但没有超时时重新发送超时操作并执行一些操作。AFNetworking重试失败的操作enqueueBatchOfHTTPRequestOperations
我真的需要弄清楚这一点,非常感谢!
[[SDAFParseAPIClient sharedClient] enqueueBatchOfHTTPRequestOperations:pagedOperations progressBlock:^(NSUInteger numberOfCompletedOperations, NSUInteger totalNumberOfOperations) {
NSLog(@"PAGED totalNumberOfOperations: %u numberOfCompletedOperations: %u",totalNumberOfOperations,numberOfCompletedOperations);
} completionBlock:^(NSArray *operations) {
NSMutableArray *retryops = [NSMutableArray array];
for(AFHTTPRequestOperation *operation in operations){
if(operation.error.code == -1001){
NSLog(@"error code %d",operation.error.code);
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"comp");
//actually original completion block is needed
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"fail");
//actually original fail block is needed
}];
[retryops addObject:operation];
//Do something with the response
}else{
//Handle the failure
}
}
if ([retryops count] == 0) {
NSLog(@"all paginated operations completed");
}
else {
[[SDAFParseAPIClient sharedClient] enqueueBatchOfHTTPRequestOperations:retryops progressBlock:
^(NSUInteger numberOfFinishedOperations, NSUInteger totalNumberOfOperations) {
} completionBlock:
^(NSArray *operations) {
NSLog(@"all retry paginated operations completed");
}];
}
您要求多少操作? – dbainbridge
@dbainbridge我将所有要同步的数据发送到服务器,所以它取决于但可能很多 - 这就是为什么有些操作会超时。 – tugce