如何使用Photos Framework在相机胶卷中仅获取图像 [英] How to get only images in the camera roll using Photos Framework

查看:108
本文介绍了如何使用Photos Framework在相机胶卷中仅获取图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码加载也位于iCloud或流图像上的图像。我们如何将搜索限制为仅限于相机胶卷中的图像?

The following code loads images that are also located on iCloud or the streams images. How can we limit the search to only images in the camera roll?

var assets = PHAsset.fetchAssetsWithMediaType(PHAssetMediaType.Image, options: nil)


推荐答案

通过一些实验我们发现了一个隐藏的属性未列在文档中( assetSource )。基本上你必须做一个常规的提取请求,然后使用谓词来过滤相机胶卷中的谓词。此值应为3.

Through some experimentation we discovered a hidden property not listed in the documentation (assetSource). Basically you have to do a regular fetch request, then use a predicate to filter the ones from the camera roll. This value should be 3.

示例代码:

//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)

这篇关于如何使用Photos Framework在相机胶卷中仅获取图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆