Skip to content

Conversation

philprime
Copy link
Member

📜 Description

This pull request introduces a targeted workaround in the SentryUIRedactBuilder to handle a crash related to CameraUI.ChromeSwiftUIView on iOS 26 when built with Xcode 16. The workaround ensures that the redaction process skips subtrees of this specific internal camera view to prevent the crash, while maintaining normal redaction behavior for other views.

Camera view crash workaround (iOS 26, Xcode 16+):

  • Added a runtime check in SentryUIRedactBuilder to detect and skip subtrees of CameraUI.ChromeSwiftUIView when running on iOS 26+ to prevent crashes from unimplemented initializers. (cameraSwiftUIViewClassObjectId, isViewSubtreeIgnored, redactRegionsFor(view:)) [1] [2] [3]

Redaction logic improvements:

  • Updated redaction region naming to use view.debugDescription instead of layer.name for more consistent identification. [1] [2]

Unit tests for workaround and redaction:

  • Added comprehensive tests to verify subtree skipping, normal redaction behavior, and that the workaround is only active under the correct conditions. [1] [2]

Camera UI integration (demo/sample):

  • Modified ErrorsViewController.swift to present the camera UI using UIImagePickerController for testing camera permission flows.

‼️ THIS WILL BE REMOVED BEFORE THE PR IS MERGED

💡 Motivation and Context

Fixes #5647

💚 How did you test it?

  • Added additional unit tests.
  • Compiled the iOS-Swift sample using Xcode 16 and ran the app in iOS 26 Beta 7

📝 Checklist

You have to check all boxes before merging:

  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.

Copy link
Contributor

github-actions bot commented Sep 2, 2025

Fails
🚫 Please consider adding a changelog entry for the next release.

Instructions and example for changelog

Please add an entry to CHANGELOG.md to the "Unreleased" section. Make sure the entry includes this PR's number.

Example:

## Unreleased

- Add exemption for CameraUI traversal for iOS 26.0 ([#6045](https://github.com/getsentry/sentry-cocoa/pull/6045))

If none of the above apply, you can opt out of this check by adding #skip-changelog to the PR description or adding a skip-changelog label.

Generated by 🚫 dangerJS against 21ce96f

/// This workaround is specifically for Xcode 16 building for iOS 26 where accessing CameraUI.ModeLoupeLayer
/// causes a crash due to unimplemented init(layer:) initializer.
private static let cameraSwiftUIViewClassObjectId: ObjectIdentifier? = {
guard let classType = NSClassFromString("CameraUI.ChromeSwiftUIView") else {
Copy link
Member

@philipphofmann philipphofmann Sep 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

h: When looking at the crash in #5647 it could be that simply calling NSClassFromString could still lead to crashes. We had a weird issue in the past when swizzling UIViewControllers (#3798) and therefore we don't call it in the SentrySubClassFinder for excluded classes

// It is vital to avoid calling NSClassFromString for the excluded classes because we
// had crashes for specific classes when calling NSClassFromString, such as
// https://github.com/getsentry/sentry-cocoa/issues/3798.
if (shouldExcludeClassFromSwizzling) {
continue;
}

I even opened a bug in the Swift repo but it never got fixed: swiftlang/swift#72657. I'm unsure if it's worth the effort to do this right now. Simply doing a check if we're running on iOS 26 could be safer.

Copy link

codecov bot commented Sep 2, 2025

❌ 104 Tests Failed:

Tests completed Failed Passed Skipped
32327 104 32223 104
View the top 3 failed test(s) by shortest run time
iOS_Swift_UITests.UserFeedbackUITests::testCancelFromFormByButton
Stack Traces | 0s run time
.../iOS-Swift/iOS-Swift-UITests/UserFeedbackUITests.swift:644 - Failed to application io.sentry.sample.iOS-Swift is not running
iOS_Swift_UITests.ViewLifecycleUITests::testViewLifecycle_callingDismissWithLoadView_shouldNotCrashSDK
Stack Traces | 0s run time
.../iOS-Swift/iOS-Swift-UITests/UITestHelpers.swift:5 - XCTAssertTrue failed - Home Screen doesn't exist.
iOS_Swift_UITests.ViewLifecycleUITests::testViewLifecycle_callingDismissWithViewWillAppear_shouldNotCrashSDK
Stack Traces | 0s run time
.../iOS-Swift/iOS-Swift-UITests/ViewLifecycleUITests.swift:59 - Failed to tap "Extra" Button: Timed out while evaluating UI query.

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

Copy link
Contributor

github-actions bot commented Sep 2, 2025

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 1214.33 ms 1249.85 ms 35.52 ms
Size 23.75 KiB 938.51 KiB 914.76 KiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
aa96485 1215.37 ms 1234.04 ms 18.67 ms
acac774 1217.76 ms 1253.29 ms 35.52 ms
5ec90e0 1235.57 ms 1258.45 ms 22.88 ms
04ff3ec 1220.71 ms 1253.86 ms 33.15 ms
67e8e3e 1220.08 ms 1229.23 ms 9.15 ms
b13e93a 1236.24 ms 1247.33 ms 11.08 ms
51b7dd3 1235.06 ms 1258.21 ms 23.15 ms
b57ee62 1218.21 ms 1248.94 ms 30.73 ms
884b224 1233.41 ms 1259.50 ms 26.09 ms
7fc6927 1221.21 ms 1242.36 ms 21.15 ms

App size

Revision Plain With Sentry Diff
aa96485 23.75 KiB 874.46 KiB 850.71 KiB
acac774 23.75 KiB 866.51 KiB 842.76 KiB
5ec90e0 23.74 KiB 872.67 KiB 848.92 KiB
04ff3ec 23.75 KiB 880.26 KiB 856.52 KiB
67e8e3e 23.75 KiB 919.91 KiB 896.16 KiB
b13e93a 23.75 KiB 855.37 KiB 831.62 KiB
51b7dd3 23.75 KiB 913.26 KiB 889.52 KiB
b57ee62 23.75 KiB 912.47 KiB 888.72 KiB
884b224 23.75 KiB 879.60 KiB 855.86 KiB
7fc6927 23.75 KiB 908.54 KiB 884.79 KiB

Previous results on branch: issue-5647

Startup times

Revision Plain With Sentry Diff
afcf7f2 1200.98 ms 1234.06 ms 33.08 ms

App size

Revision Plain With Sentry Diff
afcf7f2 23.75 KiB 933.31 KiB 909.56 KiB

@philprime philprime self-assigned this Sep 2, 2025
@philprime
Copy link
Member Author

Using NSClassFromString will load the type into the Objective-C runtime and call it's +initialize() method, which could cause side-effects. Instead I will refactor it to convert the type of the current view and compare by their string name instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SessionReplay crashes when launching the camera in an app in iOS 26
2 participants