如何在获取PHAssetCollection语句中获取“相机胶卷”,“视频”,“收藏夹”,“自拍”和“屏幕截图”-swift 4

时间:2019-04-18 08:45:24

标签: ios swift photo phasset phassetcollection

我正在使用照片框架,并尝试在iPhone上获取所有相册中的所有照片和视频。但是问题是我无法通过以下方式获取包括“相机胶卷”,“视频”,“收藏夹”,“自拍”,“屏幕截图” 其他相册在内的所有相册fetchAssetCollections语句。 我只拿了其他专辑

我已经尝试了所有albumsubtype,但这对我没有帮助。

这是我的代码:

var collections: PHFetchResult<PHAssetCollection>!

@objc private func loadPhoto(notification: Notification) {
        if let object = notification.object {
            photoArray.removeAll()

            collections = PHAssetCollection.fetchAssetCollections(with: .album, subtype: .any, options: nil)

            collections.enumerateObjects { (collection, _, _) in
                let photoInAlbum = PHAsset.fetchAssets(in: collection, options: nil)

                photoInAlbum.enumerateObjects({ (asset, _, _) in
                    let imageSize = CGSize(width: 200, height: 200)
                    let photoOption = PHImageRequestOptions()
                    photoOption.deliveryMode = .fastFormat
                    photoOption.isSynchronous = true

                    PHCachingImageManager.default().requestImage(for: asset, targetSize: imageSize, contentMode: .aspectFill, options: photoOption, resultHandler: { (image, info) in
                        self.photoArray.append(image!)
                    })
                })
            }
            listPhotoView.reloadData()
        }
    }

I expect the output is all the albums including "Camera Roll", "Videos", "Favorites", "Selfies", "Screenshots" and other albums
Sorry about my bad English

1 个答案:

答案 0 :(得分:0)

更改

collections = PHAssetCollection.fetchAssetCollections(with: .album, subtype: .any, options: nil)

collections = PHAssetCollection.fetchAssetCollections(with: . smartAlbum, subtype: .any, options: nil)

您要列出的所有相册均为“智能相册”。 .album是指用户创建的相册。