dispatch_semaphore_t semaphore control program execution sequence

 

dispatch_semaphore_t semaphore control program execution sequence

 

        //Ensure that reading the album resources is complete
        dispatch_queue_t queue = dispatch_get_global_queue(0, 0);
        //Wait for the semaphore to end the thread
        dispatch_semaphore_t sema = dispatch_semaphore_create(0);
        dispatch_async(queue, ^(){
            // get the number of photos
            [[AssetHelp sharedAssetHelper] getGroupList:[ALAssetsFilter allPhotos] cb:^(NSArray * groupList) {
                ALAssetsGroup *group = [groupList firstObject];
                //Initialize the album list element
                [[AssetHelp sharedAssetHelper] getPhotoListOfGroup:group result:^(NSArray *assetList) {
                    //Cache local album list
                    photosLocalAssetList = [assetList copy];
                    NSLog(@"----0---");
                    //Initialize image data
                    for (ALAsset *asset in assetList) {
                        MWPhoto *photo = [MWPhoto photoWithURL:asset.defaultRepresentation.url];
                        [photosLocalImport addObject:photo];
                        MWPhoto *thumb = [MWPhoto photoWithImage:[UIImage imageWithCGImage:asset.thumbnail]];
                        [thumbsLocalImport addObject:thumb];
                        // if ([asset valueForProperty: ALAssetPropertyType] == ALAssetTypeVideo) {
                        //                        photo.videoURL = asset.defaultRepresentation.url;
                        //                        thumb.isVideo = true;
                        //                    }
                    }
                    // mark the end of execution
                    dispatch_semaphore_signal(sema);
                }];
            }];
        });
        
        dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
        NSLog(@"----1---");

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326831185&siteId=291194637