我正在尝试使用异步操作请求,但在某些时候操作请求由于请求超时而失败。我如何形成我的块,以便在所有操作完成失败或完成但没有超时时重新发送超时操作并执行一些操作。
我真的需要弄清楚这一点,非常感谢!
[[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");
}];
}