快速选择特定相册中的所有照片 [英] Swift Select All Photos From Specific Photos Album

查看:56
本文介绍了快速选择特定相册中的所有照片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该应用程序可以在标准的iOS照片应用程序中创建自定义相册,但是我无法找到一种方法来收集该相册中的所有图像以在应用程序中显示.

The app can create a custom album in the standard iOS photos application, but I have been unable to find a way for the app to gather all the images from that album to be displayed within the app.

当前,该应用程序能够从所有相册中收集图像,但其中一个不是特别的.

Currently, the app is able to gather images from all the albums, just not one is particular.

let resultCollections = PHAssetCollection.fetchAssetCollectionsWithType(
                 .Album,
        subtype: .AlbumRegular,
        options: nil)

    resultCollections.enumerateObjectsUsingBlock({
        (object, index, stop) -> Void in

        let collection = object as! PHAssetCollection
        let result = PHAsset.fetchAssetsInAssetCollection(collection, options: nil)

        result.enumerateObjectsUsingBlock({
            (object, index, stop) -> Void in

            let asset = object as! PHAsset
            self.images.append(asset)

        })

    })

我看到了其他可能被标记为重复的问题,但是大多数问题都在讨论如何将UIPickerView打开到自定义相册.这可能是如何从中获取所有图像的重复项自定义相册-快速,但从未得到答复.

I have seen other questions that might be marked as duplicates, however the majority of them are talking about opening a UIPickerView to a custom album. This is a possible duplicate of How to fetch all images from custom Photo Album - swift however, it was never answered.

那么,iOS应用程序如何收集特定相册中的所有图像?

So, how can an iOS app gather all images from a particular photos album?

推荐答案

添加如下所示的fetchOptions

Add fetchOptions like below

let fetchOptions = PHFetchOptions()
fetchOptions.predicate = NSPredicate(format: "title = %@", YourAlbumTitle)
let resultCollections = PHAssetCollection.fetchAssetCollectionsWithType(.Album, subtype: .AlbumRegular, options: fetchOptions)

实际上,专辑标题不是唯一的值,它们可以重复.因此,如果您的应用访问多个相册,我建议使用如下所示的localIdentifier.

Actually, album title isn't unique value, they can duplicate. so I recommend use localIdentifier like below, if your app access multiple albums.

let fetchOptions = PHFetchOptions()
fetchOptions.predicate = NSPredicate(format: "localIdentifier = %@", YourAlbumLocalIdentifier)
let resultCollections = PHAssetCollection.fetchAssetCollectionsWithType(.Album, subtype: .AlbumRegular, options: fetchOptions)

这篇关于快速选择特定相册中的所有照片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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