仅获取PHAssetMediaTypeImage类型的照片,表单资产集合类型PHAssetCollectionTypeSmartAlbum [英] Fetch only photos of type PHAssetMediaTypeImage form asset collection type PHAssetCollectionTypeSmartAlbum
本文介绍了仅获取PHAssetMediaTypeImage类型的照片,表单资产集合类型PHAssetCollectionTypeSmartAlbum的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Photos框架来获取iOS8中的专辑列表。我能够使用
I am using the Photos framework to fetch album list in iOS8. I am able to do it using
PHFetchResult *smartAlbums = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum subtype:PHAssetCollectionSubtypeAlbumRegular options:nil];
这为我提供了所有智能相册的列表,包括视频。如何过滤此列表中的视频。我只需要图像。
This gives me a list of all smart albums including videos. How can I filter out videos from this list. I need only images.
帮助将不胜感激。谢谢。
Help would be appreciated. Thanks.
推荐答案
你应该设置fetch选项,它有一个属性谓词
,可用于过滤视频。下面是这样做的一个例子。
You should set up fetch options, its has a property predicate
, which can be used to filter videos. Below is an example of doing that.
PHFetchResult *smartAlbums = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum subtype:PHAssetCollectionSubtypeAlbumRegular options:nil];
//set up fetch options, mediaType is image.
PHFetchOptions *options = [[PHFetchOptions alloc] init];
options.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:NO]];
options.predicate = [NSPredicate predicateWithFormat:@"mediaType = %d",PHAssetMediaTypeImage];
for (NSInteger i =0; i < smartAlbums.count; i++) {
PHAssetCollection *assetCollection = smartAlbums[i];
PHFetchResult *assetsFetchResult = [PHAsset fetchAssetsInAssetCollection:assetCollection options:options];
NSLog(@"sub album title is %@, count is %ld", assetCollection.localizedTitle, assetsFetchResult.count);
if (assetsFetchResult.count > 0) {
for (PHAsset *asset in assetsFetchResult) {
//you have got your image type asset.
}
}
}
这篇关于仅获取PHAssetMediaTypeImage类型的照片,表单资产集合类型PHAssetCollectionTypeSmartAlbum的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文