Skip to content

SessionReplay crashes when launching the camera in an app in iOS 26 #5647

@xuegao-tzx

Description

@xuegao-tzx

Platform

iOS

Environment

Production

Installed

CocoaPods

Version

8.53.2

Xcode Version

16.4

Did it work on previous versions?

No

Steps to Reproduce

If options.sessionReplay.sessionSampleRate = Float(1.0) or
options.sessionReplay.onErrorSampleRate = Float(1.0) is set when initializing sentry, the app will crash when the following code is used to start the camera in the app. This only happens in iOS 26. It is normal in earlier versions of iOS.

This problem exists whether it is initialized in OC or in Swift.

actual suspend fun FileKit.openCameraPicker(
    type: FileKitCameraType
): PlatformFile? = withContext(Dispatchers.Main) {
    suspendCoroutine { continuation ->
        cameraControllerDelegate = CameraControllerDelegate(
            onImagePicked = { image ->
                if (image != null) {
                    // Convert UIImage to NSData (JPEG format with compression quality 1.0)
                    val imageData = UIImageJPEGRepresentation(image, 1.0)

                    // Get the path for the temporary directory
                    val tempDir = NSTemporaryDirectory()
                    val fileName = "image_${NSUUID().UUIDString}.jpg"
                    val filePath = tempDir + fileName

                    // Create an NSURL for the file path
                    val fileUrl = NSURL.fileURLWithPath(filePath)

                    // Write the NSData to the file
                    if (imageData?.writeToURL(fileUrl, true) == true) {
                        // Return the NSURL of the saved image file
                        continuation.resume(PlatformFile(fileUrl))
                    } else {
                        // If saving fails, return null
                        continuation.resume(null)
                    }
                } else {
                    continuation.resume(null)
                }
            }
        )

        val pickerController = UIImagePickerController()
        pickerController.sourceType =
            UIImagePickerControllerSourceType.UIImagePickerControllerSourceTypeCamera
        pickerController.delegate = cameraControllerDelegate

        UIApplication.sharedApplication.firstKeyWindow?.rootViewController?.presentViewController(
            pickerController,
            animated = true,
            completion = null
        )
    }
}

This is a screenshot of xcode:

Image Image Image

This is a screenshot of Sentry:

Image Image

Expected Result

Don't Crash

Actual Result

App Crash

Are you willing to submit a PR?

No response

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions