GCD waits for multiple requests in AFN to complete the next request

There are six requests, the first five requests for asynchronous requests, and the first of the sixth requests to get the data of the first five requests:

Dispatch_queue_t queue = dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); dispatch_async (queue, group = dispatch_group_create (dispatch_group_t ^{); dispatch_group_async (group, queue, ^{[self onePositiveImageUpload: self.positiveImageView.image];}); dispatch_group_async (group, queue, ^{[self oneReverseImageUpload:self.reverseImageView.image];}); dispatch_group_async (group, queue, ^{[self moreFirstImageUploadWithArray:self.houseCardArray];} (dispatch_group_async); group, queue, ^{[self moreSecondImageUploadWithArray:self.leaseArray];}); dispatch_group_async (group, queue, [se ^{ LF moreThirdImageUploadWithArray:self.applicantArray];}); / / after waiting for the above request is completed and then execute the steps inside the dispatch_group_notify (group, queue, ^{[self requestSaveHouseMaterial];});});

But the project we generally use the AFN request, and then use this format is not. Cause I got the last request at the beginning of the first few did not get the request after the completion of the data. Then you can use this method.

To create a global group dispatch_group_t _group; in the first few dispatch_group_enter are added in the request (_group); the success or failure of adding dispatch_group_leave (_group); such as: dispatch_group_enter (_group); AFHTTPRequestOperationManager *mgr = [AFHTTPRequestOperationManager manager]; mgr.responseSerializer.acceptableContentTypes [NSSet setWithObjects:@ = "application/json", "text/html", @ nil]; / / the 2 parameters (package this dictionary can only put the non parameter files) NSMutableDictionary * params [NSMutableDictionary dictionary] = 2; / / send a request [mgr (id< POST:UPLOAD_IMAGE_URL parameters:params constructingBodyWithBlock:^; AFMultipartFormData> formData) {NSMutableArray *arr = [NSMutableArray array]; for (int = I 0; I < array.count; I) {NSData = UIImageJPEGRepresentation + *fileData (array[i], 0.05); [arr addObject:fileData];} for (int i = 0; I < arr.count I; [formData appendPartWithFileData:arr[i] name:[NSString + +) {stringWithFormat:@ "filestream%d" i] fileName:[NSString stringWithFormat:@ "zhengshu%d.jpg" i], mimeType:@ "image/jpeg"];}} success:^ (AFHTTPRequestOperation *operation, ID responseObject) {NSMutableDictionary *data responseObject[@ = "data"]; / / *array = [data[@ picture array NSArray "fileName" componentsSeparatedByString:@ "," NSMutableArray *urlArr = [NSMutableArray; array]; for (int i = 0; I < array.cou NT; I) {NSString + + *url = [array[i] lastPathComponent]; [urlArr addObject:url]; self.thirdString [urlArr componentsJoinedByString:@} = "dispatch_group_leave"]; (_group);} failure:^ (AFHTTPRequestOperation *operation, NSError * error) {[SMGlobalMethod showMessage:NetNoti]; dispatch_group_leave (_group);}]; request when written on this OK. Dispatch_queue_t (queue = dispatch_get_global_queue DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); dispatch_async (queue, _group = dispatch_group_create (^{); dispatch_group_async (_group, queue, ^{[self onePositiveImageUpload:self.positiveImageView.image];}; dispatch_group_async (_gr) OUP, queue, ^{[self oneReverseImageUpload:self.reverseImageView.image];}); dispatch_group_async (_group, queue, ^{[self moreFirstImageUploadWithArray:self.houseCardArray];}); dispatch_group_async (_group, queue, ^{[self moreSecondImageUploadWithArray:self.leaseArray];}); dispatch_group_async (_group, queue, ^{[self moreThirdImageUploadWithArray:self.applicantArray];}); / / for the above request with adding dispatch_group_enter and dispatch_group_leave, so really wait the above thread completes execution of the request to dispatch_group_notify it (_group, queue, ^{[self requestSaveHouseMaterial];});}); this When we use AFN to request data, we really do wait for multiple requests to complete and then execute the next request

Because it is encountered in the project, so just write a bit, at noon to write a Demo. (just to learn about the use of GitHub, had never submitted to the above code. And…). The code above is not the same. Lists three different ways to help we want to see a resolution. You can go and see