#pragma mark -- iOS 8.0 以上獲取所有照片用Photos.h這個(gè)庫(kù)
-(NSMutableArray *)getALLphotosUsingPohotKit
{
? ? NSMutableArray *arr = [NSMutableArray array];
? ? // 所有智能相冊(cè)
? ? PHFetchResult *smartAlbums = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum subtype:PHAssetCollectionSubtypeAlbumRegular options:nil];
? ? for (NSInteger i = 0; i < smartAlbums.count; i++) {
? ? ? ? @autoreleasepool {
? ? ? ? ? ? // 是否按創(chuàng)建時(shí)間排序
? ? ? ? ? ? PHFetchOptions *option = [[PHFetchOptions alloc] init];
? ? ? ? ? ? option.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:YES]];
? ? ? ? ? ? option.predicate = [NSPredicate predicateWithFormat:@"mediaType == %ld", PHAssetMediaTypeImage];
? ? ? ? ? ? PHCollection *collection = smartAlbums[i];
? ? ? ? ? ? //遍歷獲取相冊(cè)
? ? ? ? ? ? if ([collection isKindOfClass:[PHAssetCollection class]]) {
? ? ? ? ? ? ? ? if ([collection.localizedTitle isEqualToString:@"所有照片"]) {
? ? ? ? ? ? ? ? ? ? PHAssetCollection *assetCollection = (PHAssetCollection *)collection;
? ? ? ? ? ? ? ? ? ? PHFetchResult *fetchResult = [PHAsset fetchAssetsInAssetCollection:assetCollection options:nil];
? ? ? ? ? ? ? ? ? ? NSArray *assets;
? ? ? ? ? ? ? ? ? ? if (fetchResult.count > 0) {
? ? ? ? ? ? ? ? ? ? ? ? // 某個(gè)相冊(cè)里面的所有PHAsset對(duì)象
? ? ? ? ? ? ? ? ? ? ? ? assets = [self getAllPhotosAssetInAblumCollection:assetCollection ascending:YES ];
? ? ? ? ? ? ? ? ? ? ? ? [arr addObjectsFromArray:assets];
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? }
? ? }
? ? //返回所有照片內(nèi)的所有照片
? ? return arr;
}
#pragma mark - <? 獲取相冊(cè)里的所有圖片的PHAsset對(duì)象? >
- (NSArray *)getAllPhotosAssetInAblumCollection:(PHAssetCollection *)assetCollection ascending:(BOOL)ascending
{
? ? // 存放所有圖片對(duì)象
? ? NSMutableArray *assets = [NSMutableArray array];
? ? // 是否按創(chuàng)建時(shí)間排序
? ? PHFetchOptions *option = [[PHFetchOptions alloc] init];
? ? option.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:ascending]];
? ? option.predicate = [NSPredicate predicateWithFormat:@"mediaType == %ld", PHAssetMediaTypeImage];
? ? // 獲取所有圖片對(duì)象
? ? PHFetchResult *result = [PHAsset fetchAssetsInAssetCollection:assetCollection options:option];
? ? // 遍歷
? ? [result enumerateObjectsUsingBlock:^(PHAsset *asset, NSUInteger idx, BOOL * _Nonnull stop) {
? ? ? ? [assets addObject:asset];
? ? }];
? ? return assets;
}
調(diào)用方法:

其中,filename就是圖片名字;格式:IMG_0776.JPG