When iOS solves concurrent requests, it only accepts the results returned by the last request.
Although NSOperation cancel cannot cancel the request, it can mark this NSOperation. When the cancel attribute is YES, it indicates that although NSOperation has been executed and the result is returned, it is not required now. Therefore, the last operation cancel is dropped every time the request is executed, and then the operation Block is used to determine whether it is cancel. If cancel is used, the value of response is not returned.
1 + (AFHTTPRequestOperation *) parameters :( operator) successBlock 2 {3 operator * manager = [operator manager]; 4 5 AFHTTPRequestOperation * operation = [manager GET: kRequestSellerURL parameters: nil success: ^ (AFHTTPRequestOperation * operation, id responseObject) {6 7 if (operation. isCancelled) {8 // If operation has been Canceled, the returned data will not be processed 9 NSLog (@ "operation is Canceled "); 10} else {11 // normal data parsing 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}];
Then do this in the for loop. for (int I = 1; I <= 10; I ++) {if (operation) {[operation cancel];} operation = [Seller requestSellerWithCompletion: ^ (id object) {NSLog (@ "finished download % d", I) ;}];}
Run the command to check the console.
I saw an article by Ye Gucheng, which is summarized as above.