The general meaning is that although nsoperation cancel cannot cancel the request, the nsoperation can be flagged. When the Cancel property is Yes, it indicates that Nsoperation has executed and returned the result, but I don't need it now. Then we cancel the last operation every time we execute the request, and then in completion block we judge if operation Cancel, and if Cancel does not return the value of response.
1+ (Afhttprequestoperation *) Requestsellerwithcompletion: (requestfinishedcompletionblock) Successblock2 {3Afhttprequestoperationmanager *manager =[Afhttprequestoperationmanager manager];4 5afhttprequestoperation * operation = [manager get:krequestsellerurl parameters:nil success:^ (AFHTTPRequestOperation * Operation,IDresponseobject) {6 7 if(operation.iscancelled) {8 //If the operation has been cancel, the return data will not be processed9NSLog (@"operation is Canceled");Ten}Else{ One //Normal data parsing if no cancel is removed ANsarray *sellerarray = [Mtljsonadapter modelsofclass:[sellerclass] Fromjsonarray:responseobject[@"Data"] Error:nil]; - if(successblock) { - //NSLog (@ "Current operation Count is%d", [Manager.operationqueue operations].count); the Successblock (sellerarray); - } - } - + -} failure:^ (Afhttprequestoperation *operation, Nserror *error) { + A}];
then do so in the for loop. for (int1; i++) { if (operation) { [operation Cancel]; } = [Seller requestsellerwithcompletion:^ (IDObject) { NSLog (@ "finished download%d", I); }]; }
Run a look at the console.
See ye isolated City an article, and now summarize it myself as above
How IOS resolves concurrent requests, accepting only the results returned by the last request