Post

Replies

Boosts

Views

Activity

Reply to [iOS 18.0] PHImageManager request image crash
The app crashes when attempting to fetch the latest image from the gallery. The crash occurs specifically when the latest image is a freshly captured photo from the native Camera app. var allPhotosOptions: PHFetchOptions { let fetchOptions = PHFetchOptions() fetchOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: false)] fetchOptions.predicate = NSPredicate(format: "mediaType = \(PHAssetMediaType.image.rawValue)") return fetchOptions } func requestImageFromPhotoLibrary() { var selectedAssets = [String]() let allPhotos = PHAsset.fetchAssets(with: allPhotosOptions) let firstAsset = allPhotos.firstObject?.localIdentifier selectedAssets.append(firstAsset ?? "") let assetResult = PHAsset.fetchAssets(withLocalIdentifiers: selectedAssets, options: nil) // Perform assets creation in background thread DispatchQueue.global(qos: .background).async { [weak self] in if let phAsset = assetResult.firstObject { let options = PHImageRequestOptions() options.isNetworkAccessAllowed = true options.deliveryMode = .highQualityFormat let resultHandler: (Data?, String?, CGImagePropertyOrientation, [AnyHashable: Any]?) -> Void = { [weak self] (data, _, _, _) in guard let self = self else { return } if let imageData = data, let assetImage = UIImage(data: imageData) { print("Image size: \(assetImage.size)") } else { print("Didn't get assets from PhotosFramework") } } PHImageManager.default().requestImageDataAndOrientation(for: phAsset, options: options, resultHandler: resultHandler) } } }
May ’25
Reply to [iOS 18.0] PHImageManager request image crash
I noticed that this crash is only happening when we are trying to request an asset which was clicked using Apple native camera.
Replies
Boosts
Views
Activity
May ’25
Reply to [iOS 18.0] PHImageManager request image crash
The app crashes when attempting to fetch the latest image from the gallery. The crash occurs specifically when the latest image is a freshly captured photo from the native Camera app. var allPhotosOptions: PHFetchOptions { let fetchOptions = PHFetchOptions() fetchOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: false)] fetchOptions.predicate = NSPredicate(format: "mediaType = \(PHAssetMediaType.image.rawValue)") return fetchOptions } func requestImageFromPhotoLibrary() { var selectedAssets = [String]() let allPhotos = PHAsset.fetchAssets(with: allPhotosOptions) let firstAsset = allPhotos.firstObject?.localIdentifier selectedAssets.append(firstAsset ?? "") let assetResult = PHAsset.fetchAssets(withLocalIdentifiers: selectedAssets, options: nil) // Perform assets creation in background thread DispatchQueue.global(qos: .background).async { [weak self] in if let phAsset = assetResult.firstObject { let options = PHImageRequestOptions() options.isNetworkAccessAllowed = true options.deliveryMode = .highQualityFormat let resultHandler: (Data?, String?, CGImagePropertyOrientation, [AnyHashable: Any]?) -> Void = { [weak self] (data, _, _, _) in guard let self = self else { return } if let imageData = data, let assetImage = UIImage(data: imageData) { print("Image size: \(assetImage.size)") } else { print("Didn't get assets from PhotosFramework") } } PHImageManager.default().requestImageDataAndOrientation(for: phAsset, options: options, resultHandler: resultHandler) } } }
Replies
Boosts
Views
Activity
May ’25
Reply to [iOS 18.0] PHImageManager request image crash
Hi, the issue on our app is intermittent and it's happening with the above code snippet. I tried implementing the same with sample app myself and it was not happening. So is there any build settings or any other settings which might be causing this?
Replies
Boosts
Views
Activity
May ’25