AFNetworking使用enqueueBatchOfHTTPRequestOperations重试超时请求

时间:2013-01-17 12:07:34

标签: ios afnetworking nsurlrequest

我的答案中几乎没有类似的问题,但找不到在我的代码上使用该解决方案的方法。我很高兴,如果有人可以帮助我代码。如何重试超时请求?

阻止分页目的:

while(mult < (int)totalCount) {

     AFHTTPRequestOperation *opr = [self getRequestForAllRecordsOfClass:className updatedAfterDate:mostRecentUpdatedDate withinPage:page+1];
     [pagedOperations addObject:opr];
     mult = mult + PAGINATION_SIZE;
     page = page + 1;
}

    [[SDAFParseAPIClient sharedClient] enqueueBatchOfHTTPRequestOperations:operations progressBlock:^(NSUInteger numberOfCompletedOperations, NSUInteger totalNumberOfOperations) {
             NSLog(@"totalNumberOfOperations: %u  numberOfCompletedOperations: %u",totalNumberOfOperations,numberOfCompletedOperations);
        } completionBlock:^(NSArray *operations) {
                     ...
}];

并构建请求操作

-(AFHTTPRequestOperation *)getRequestForAllRecordsOfClass:(NSString *)className updatedAfterDate:(NSDate *)mostRecentDate withinPage:(int)page  {

    NSMutableURLRequest *request = [ZurmoHelper GETRequestForAllRecordsOfClass:className updatedAfterDate:mostRecentDate inPage:page];

    AFHTTPRequestOperation *operation = [[SDAFParseAPIClient sharedClient] HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject) {

        NSLog(@"RESPONSE pagination!!! %@:", className);
        NSError *error = nil; //error in parsing json
        NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:responseObject options:kNilOptions error:&error];

        if (!error) {
            NSLog(@"json dict paged in : %d",page );
            id dataObject = [jsonDict objectForKey:@"data"];
            NSArray *itemsObject = [dataObject objectForKey:@"items"];
            [self addItems:itemsObject className:className];
        }

    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {

        NSLog(@"Request for class %@ failed with error: %@", className, error);
        if (error.code == -1001) {
            NSLog(@"for class %@ page: %d,",className,page);
            //need to retry this operation???
        }
    }];

    return operation;

}

0 个答案:

没有答案