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