Post not yet marked as solved
Post marked as unsolved with 0 replies, 1,981 views
Hello everyone, I am trying to fetch a list of photo albums from the photo library and present it to the user to select one of them. I have the following code below which fetches the list of photo albums. I can see all the photo albums list in the output on xcode but it's not presenting to the user. How can I get it to present to the user?func getPhotosFromAlbum(albumName: BeenThereItem)
{
var photoLibraryImages = [UIImage]()
var photoLibraryAssets = [PHAsset]()
let finalPhotos = albumName.photoAlbum
DispatchQueue.global(qos: .userInteractive).async
{
let fetchOptions = PHFetchOptions()
fetchOptions.predicate = NSPredicate(format: "mediaType = %d", PHAssetMediaType.image.rawValue)
let smartAlbums = PHAssetCollection.fetchAssetCollections(with: .smartAlbum, subtype: .any, options: nil)
let customAlbums = PHAssetCollection.fetchAssetCollections(with: .album, subtype: .any, options: nil)
[smartAlbums, customAlbums].forEach {
$0.enumerateObjects { collection, index, stop in
let imgManager = PHImageManager.default()
let requestOptions = PHImageRequestOptions()
requestOptions.isSynchronous = true
requestOptions.deliveryMode = .highQualityFormat
// let photoInAlbum = PHAsset.fetchAssets(in: collection, options: fetchOptions)
let photoInAlbum = PHAsset.fetchAssets(in: collection, options: fetchOptions)
if let title = collection.localizedTitle
{
if photoInAlbum.count > 0
{
print("\n\n \(title) --- count = \(photoInAlbum.count) \n\n")
}
if title == albumName.photoAlbum
{
if photoInAlbum.count > 0
{
for i in (0..<photoInAlbum.count).reversed()
{
imgManager.requestImage(for: photoInAlbum.object(at: i) as PHAsset , targetSize: CGSize(width: 150, height: 150), contentMode: .aspectFit, options: requestOptions, resultHandler: {
image, error in
if image != nil
{
photoLibraryImages.append(image!)
photoLibraryAssets.append(photoInAlbum.object(at: i))
}
})
}
}
}
}
}
}
}
}