使用dispatch_semaphore_t
實(shí)現(xiàn) dispatch_semaphore_t sema = dispatch_semaphore_create(0);
//創(chuàng)建信號(hào)量
__block ALAssetsGroup *ret = nil; ALAssetsLibraryGroupsEnumerationResultsBlock listGroupBlock = ^(ALAssetsGroup *group, BOOL *stop) { ret = group; dispatch_semaphore_signal(sema); //關(guān)鍵點(diǎn)症革,在此發(fā)送信號(hào)量 };
?ALAssetsLibraryAccessFailureBlock failureBlock = ^(NSError *error) { ret = nil; dispatch_semaphore_signal(sema); //關(guān)鍵點(diǎn)筐咧,失敗時(shí)發(fā)送 };
NSUInteger groupTypes = ALAssetsGroupSavedPhotos;
[self.assetsLibrary enumerateGroupsWithTypes:groupTypes usingBlock:listGroupBlock failureBlock:failureBlock];
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER); //關(guān)鍵點(diǎn),在此等待信號(hào)量 return ret;