I am working with Photo framework and try to fetch all photos & videos in all albums on iPhone. But the problem is I can't fetch all albums including "Camera Roll", "Videos", "Favorites", "Selfies", "Screenshots" and others albums with the fetchAssetCollections
statement.
I have only fetched others albums.
I have tried all of the album
and subtype
, but it doesn't help me.
Here is my code:
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 others albums.
Change
to
All albums you want to list are "Smart Albums". .album refers to user created albums.