[iOS] photoKit获取所有照片
生活随笔
收集整理的這篇文章主要介紹了
[iOS] photoKit获取所有照片
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
代碼:
- (NSMutableArray *)getAllPhoto{NSMutableArray *arr = [NSMutableArray array];// 所有智能相冊PHFetchResult *smartAlbums = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum subtype:PHAssetCollectionSubtypeAlbumRegular options:nil];for (NSInteger i = 0; i < smartAlbums.count; i++) {PHCollection *collection = smartAlbums[i];//遍歷獲取相冊if ([collection isKindOfClass:[PHAssetCollection class]]) {PHAssetCollection *assetCollection = (PHAssetCollection *)collection;PHFetchResult *fetchResult = [PHAsset fetchAssetsInAssetCollection:assetCollection options:nil];PHAsset *asset = nil;if (fetchResult.count != 0) {for (NSInteger j = 0; j < fetchResult.count; j++) {//從相冊中取出照片asset = fetchResult[j];PHImageRequestOptions *opt = [[PHImageRequestOptions alloc]init];opt.synchronous = YES;PHImageManager *imageManager = [[PHImageManager alloc] init];[imageManager requestImageForAsset:asset targetSize:PHImageManagerMaximumSize contentMode:PHImageContentModeAspectFill options:opt resultHandler:^(UIImage * _Nullable result, NSDictionary * _Nullable info) {if (result) {[arr addObject:result];}}];}}}}//返回所有照片return arr;由于此方法為同步方法 所以需要放在子線程中去執行 例如:
dispatch_async(dispatch_get_global_queue(0, 0), ^{NSMutableArray *arr = [self getAllPhoto];NSLog(@"完成%@ \n照片總數%ld", arr, arr.count);});?轉載于:https://www.cnblogs.com/iwgo/p/5549731.html
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的[iOS] photoKit获取所有照片的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: jedate选中日期后关闭弹层_jeDa
- 下一篇: eclipse创建folder变成pac