PHCacheImageManager.requestAVAsset(forVideo:...) returns nil AVAsset PHCacheImageManager.requestAVAsset(forVideo:...) returns nil AVAsset swift swift

PHCacheImageManager.requestAVAsset(forVideo:...) returns nil AVAsset


It looks like I was trying to request video assets that were stored in iCloud without setting the video request options to allow network access.

When requesting the video from the PHCachingImageManager, I failed to pass any PHVideoRequestOptions object. Adding the lines below just prior to requesting the asset fixes this.

let options = PHVideoRequestOptions()options.isNetworkAccessAllowed = true

I found this thread on an open source image picker using the Photos framework. The videos I was testing with were indeed in iCloud which caused my returned asset to be nil. The linked thread also has a good example of hooking up a progress handler in objective C:

options.networkAccessAllowed = YES;options.progressHandler = ^(double progress, NSError *error, BOOL *stop, NSDictionary *info){...};