1

我正在使用 Photo 框架并尝试获取 iPhone 上所有相册中的所有照片和视频。但问题是我无法获取所有专辑,包括“Camera Roll”“Videos”“Favorites”“Selfies”“Screenshots”其他带有fetchAssetCollections声明的专辑。我只取了别人的专辑。

我已经尝试了所有的albumand subtype,但它对我没有帮助。

这是我的代码:

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()
        }
    }

我希望输出是所有专辑,包括“Camera Roll”“Videos”“Favorites”“Selfies”“Screenshots”其他专辑

4

1 回答 1

2

改变

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

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

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

于 2019-05-19T15:29:15.070 回答