ios - 如何在 fetch PHAssetCollection 语句中获取 "Camera Roll"、 "Videos"、 "Favorites"、 "Selfies"和 "Screenshots"- swift 4

标签 ios swift photo phasset phassetcollection

我正在使用照片框架,并尝试获取 iPhone 上所有相册中的所有照片和视频。但问题是我无法获取所有相册,包括“相机胶卷”“视频”“收藏夹””使用 fetchAssetCollections 语句的“Selfies”“Screenshots”其他相册。 我只获取了其他专辑。

我已经尝试了所有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()
        }
    }

我希望输出是所有专辑,包括“相机胶卷”“视频”“收藏夹”” “自拍照”“屏幕截图”其他相册

最佳答案

改变

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

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

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

关于ios - 如何在 fetch PHAssetCollection 语句中获取 "Camera Roll"、 "Videos"、 "Favorites"、 "Selfies"和 "Screenshots"- swift 4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55742322/

相关文章:

ios - 单击 swift ios 中的按钮时如何显示文本字段?

facebook - 使用 Facebook 实时更新检测照片上传

java - 以编程方式通过 android 上的 imgur 上传照片

java - Android 相机预览中的单帧图像

android - Ionic Cordova QrScanner 布局不一致?

iphone - 有人在 iPhone 应用程序中成功使用 CFAllocatorSet Default 吗?

php - iOS 无法通过 PHP 在 iPhone 应用程序和 MySQL 数据库之间进行通信

iphone - iOS向大量用户推送通知

ios - Swift 在 VC 之间传递数据

ios - 与 assetsd 的连接中断或 assetsd 死亡