bho*_*omi 16 photolibrary ios photokit phasset
我正在使用Photos框架来获取iOS8中的专辑列表.我能够使用它
PHFetchResult *smartAlbums = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum subtype:PHAssetCollectionSubtypeAlbumRegular options:nil];
Run Code Online (Sandbox Code Playgroud)
这给了我所有智能相册的列表,包括视频.如何过滤此列表中的视频.我只需要图像.
帮助将不胜感激.谢谢.
gab*_*ler 28
您应该设置提取选项,它有一个属性predicate,可用于过滤视频.以下是这样做的一个例子.
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.
}
}
}
Run Code Online (Sandbox Code Playgroud)
Max*_*Max 24
在swift中做同样的事情:
let fetchOptions = PHFetchOptions()
fetchOptions.predicate = NSPredicate(format: "mediaType = %d", PHAssetMediaType.Image.rawValue)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13014 次 |
| 最近记录: |