1 + (AFHTTPRequestOperation *)requestSellerWithCompletion:(requestFinishedCompletionBlock)successBlock 2 { 3 AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; 4 5 AFHTTPRequestOperation * operation = [manager GET:kRequestSellerURL parameters:nil success:^(AFHTTPRequestOperation *operation, id responSEObject) { 6 7 if (operation.isCancelled) { 8 //若果operation已經被cancel了,則不對返回數據進行處理 9 NSLog(@"operation is Canceled");10 }else{11 //如果沒有cancel 掉,則進行正常的數據解析12 NSArray *sellerArray = [MTLJSONAdapter modelsOfClass:[Seller class] fromJSONArray:responseObject[@"data"] error:nil];13 if (successBlock) {14 // NSLog(@"current operation count is %d",[manager.operationQueue operations].count);15 successBlock(sellerArray);16 }17 }18 19 20 } failure:^(AFHTTPRequestOperation *operation, NSError *error) {21 22 }];
然后在for循環里這么做.for (int i = 1; i <= 10; i++) { if (operation) { [operation cancel]; } operation = [Seller requestSellerWithCompletion:^(id object) { NSLog(@"finished download %d",i); }]; }
運行一下看看console .
|
新聞熱點
疑難解答