以下代码加载也位于iCloud或流图像上的图像。如何将搜索范围限制为仅相机胶卷中的图像?
var assets = PHAsset.fetchAssetsWithMediaType(PHAssetMediaType.Image, options: nil)
通过一些实验,我们发现了文档(assetSource)中未列出的隐藏属性。基本上,您必须执行常规的提取请求,然后使用谓词从相机胶卷中过滤谓词。该值应为3。
assetSource
样例代码:
//fetch all assets, then sub fetch only the range we need var assets = PHAsset.fetchAssetsWithMediaType(PHAssetMediaType.Image, options: fetchOptions) assets.enumerateObjectsUsingBlock { (obj, idx, bool) -> Void in results.addObject(obj) } var cameraRollAssets = results.filteredArrayUsingPredicate(NSPredicate(format: "assetSource == %@", argumentArray: [3])) results = NSMutableArray(array: cameraRollAssets)