I have iPhone 15 Pro Max.
private func fetchAssetsForHeader() -> [PHAsset] {
let fetchLastOptions = PHFetchOptions()
fetchLastOptions.fetchLimit = MediaPickerRootConstants.maxItemsCount
fetchLastOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: false)]
fetchLastOptions.predicate = NSPredicate(format: "(mediaType = %d AND duration < (MediaPickerRootConstants.maxVideoLength)) || (mediaType = %d)", PHAssetMediaType.video.rawValue, PHAssetMediaType.image.rawValue)
return PHAsset.fetchAssets(with: fetchLastOptions).toArray
}
private let imageRequestOptions: PHImageRequestOptions = {
let options = PHImageRequestOptions()
options.version = .current
options.resizeMode = .fast
options.deliveryMode = .fastFormat
// options.isSynchronous = true
options.isNetworkAccessAllowed = true
return options
}()
PHImageManager.default().requestImage(for: viewModel.asset,
targetSize: MediaPickerRootConstants.mediaItemSize,
contentMode: .aspectFill,
options: self.imageRequestOptions)
The problem that if PHAuthorizationStatus
is .limited
and PHImageRequestOptions
is .fastFormat
, that requestImage return nil with error:
Optional([AnyHashable("PHImageErrorKey"): Error Domain=PHPhotosErrorDomain Code=3303 "(null)", AnyHashable("PHImageResultIsDegradedKey"): 0, AnyHashable("PHImageResultRequestIDKey"): 1])
If I change PHAuthorizationStatus
to .authorized
or remove .fastFormat
deliveryMode, image fetch successfully. What can be an issue with that?