ios - fetchAssetCollectionsWithType 仅检索视频

标签 ios swift ios8 photosframework

我正致力于在 iOS 中制作自定义 Gallery View 为此,我正在使用迄今为止效果很好的照片框架 我无法让它工作的一件事是获取结果以仅返回 VIDEOS

我试过了 let result = PHAssetCollection.fetchAssetCollectionsWithType(.Moment,子类型:.SmartAlbumVideos,选项:nil) 但它仍在检索图像我想知道语法是否错误

感谢帮助

最佳答案

好的,我找到了问题的答案 基本上我需要使用一个谓词,这基本上是说检索媒体类型为视频的 Assets ,并按创建日期对其进行排序

let allVideosOptions = PHFetchOptions()
allVideosOptions.predicate = NSPredicate(format: "mediaType == %d", PHAssetMediaType.Video.rawValue)
allVideosOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: false)]
videos = PHAsset.fetchAssetsWithOptions(allVideosOptions)

关于ios - fetchAssetCollectionsWithType 仅检索视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33026480/

相关文章:

ios - 减小 iPhone 模拟器窗口的大小?

ios - 如何从 UIImagepicker 中选取动画图像并将其添加到 UIimageview 并上传

ios - 为什么我需要为音频创建一个共享实例?

ios - 音频无法在 Cordova iOS 8 中播放

ios - Core Graphics - 有没有办法从 CGContext 获取/检索当前设置的 CGColor?

ios - 来自 iOS 的自定义 HTTP 请求被拒绝

ios - 如何释放SKTexture创建的内存

swift - 实例成员不能用于类型 - Firebase

ios - 在 Swift 中展开 Optional Int

swift - Cocoapods 0.35 构建失败