From 6e625c574d5a1e4ed239d03cc498bb77677951cb Mon Sep 17 00:00:00 2001 From: jasio Date: Wed, 29 Nov 2023 17:03:12 +0800 Subject: [PATCH] fix: Crash when UINavigationController without rootViewController (#3455) When a UINavigationController is not initialized with initWithRootViewController, it leads to a crash Co-authored-by: Dhiogo Brustolin --- CHANGELOG.md | 7 +++++++ Sources/Sentry/SentryUIApplication.m | 5 ++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ec371f7d6f2..ff6cfab1e44 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## Unreleased + + +### Fixes + +- Crash when UINavigationController doesn't have rootViewController (#3455) + ## 8.17.0 ### Features diff --git a/Sources/Sentry/SentryUIApplication.m b/Sources/Sentry/SentryUIApplication.m index 92dd459185a..7c330efc23d 100644 --- a/Sources/Sentry/SentryUIApplication.m +++ b/Sources/Sentry/SentryUIApplication.m @@ -204,7 +204,10 @@ - (BOOL)isContainerViewController:(UIViewController *)viewController (UIViewController *)containerVC { if ([containerVC isKindOfClass:UINavigationController.class]) { - return @[ [(UINavigationController *)containerVC topViewController] ]; + if ([(UINavigationController *)containerVC topViewController]) { + return @[ [(UINavigationController *)containerVC topViewController] ]; + } + return nil; } if ([containerVC isKindOfClass:UITabBarController.class]) { UITabBarController *tbController = (UITabBarController *)containerVC;