I'm using [PHCachingImageManager] to cache videos in a collection view. I can display the images generated with the cache manager, but pulling AVAssets isn't working.
I try to get an AVAsset by using the .requestAVAsset(forVideo:...) method but the [asset] that is returned to the result handler is nil. I get an error when trying to unwrap the returned [asset].
I also looked at the [audioMix] and [info] parameters returned to the result handler and they were nil was well. Does anyone know what I'm doing wrong/missing here?
viewDidLoad() {
let videosAlbum = PHAssetCollection.fetchAssetCollections(with: .smartAlbum, subtype: .smartAlbumVideos, options: nil)
self.videoAssets = PHAsset.fetchAssets(in: videosAlbum.object(at: 0), options: nil)
self.imgCacheManager.startCachingImages(for: self.videoAssets.objects(at: [0, videoAssets.count-1]), targetSize: CGSize(width: 150, height: 150), contentMode: .aspectFit, options: nil)
}
override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let selectedAsset = self.imgCacheManager.requestAVAsset(forVideo: self.videoAssets.object(at: indexPath.item), options: nil, resultHandler: {
asset,_,_ in
self.delegate.selectedVideo(Asset: asset!) // this is the line I get the error
})
}
My delegate is an optional but for sure has something in it, so I'm confident it's the unwrapped [asset] that's throwing the error.