Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions Sources/Sentry/SentryUIApplication.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#import "SentryUIApplication.h"
#import "SentryInternalDefines.h"
#import "SentryLogC.h"
#import "SentrySwift.h"

Expand Down Expand Up @@ -96,7 +97,7 @@ - (UIApplication *)sharedApplication
id<UIApplicationDelegate> appDelegate = [self getApplicationDelegate:app];

if ([appDelegate respondsToSelector:@selector(window)] && appDelegate.window != nil) {
[result addObject:appDelegate.window];
[result addObject:SENTRY_UNWRAP_NULLABLE(UIWindow, appDelegate.window)];
}

windows = [result allObjects];
Expand Down Expand Up @@ -164,15 +165,16 @@ - (UIApplication *)sharedApplication
UIViewController *topVC = result[index];
// If the view controller is presenting another one, usually in a modal form.
if (topVC.presentedViewController != nil) {

if ([topVC.presentationController isKindOfClass:UIAlertController.class]) {
UIViewController *_Nonnull topPresentationVC
= SENTRY_UNWRAP_NULLABLE(UIViewController, topVC.presentedViewController);
if ([topPresentationVC isKindOfClass:UIAlertController.class]) {
// If the view controller being presented is an Alert, we know that
// we reached the end of the view controller stack and the presenter is
// the top view controller.
break;
}

[result replaceObjectAtIndex:index withObject:topVC.presentedViewController];
[result replaceObjectAtIndex:index withObject:topPresentationVC];

continue;
}
Expand Down Expand Up @@ -225,18 +227,18 @@ - (BOOL)isContainerViewController:(UIViewController *)viewController
(UIViewController *)containerVC
{
if ([containerVC isKindOfClass:UINavigationController.class]) {
if ([(UINavigationController *)containerVC topViewController]) {
return @[ [(UINavigationController *)containerVC topViewController] ];
UIViewController *_Nullable containerTopVC =
[(UINavigationController *)containerVC topViewController];
if (containerTopVC) {
return @[ SENTRY_UNWRAP_NULLABLE(UIViewController, containerTopVC) ];
}
return nil;
}
if ([containerVC isKindOfClass:UITabBarController.class]) {
UITabBarController *tbController = (UITabBarController *)containerVC;
NSInteger selectedIndex = tbController.selectedIndex;
if (tbController.viewControllers.count > selectedIndex) {
return @[ [tbController.viewControllers objectAtIndex:selectedIndex] ];
} else {
return nil;
return @[ SENTRY_UNWRAP_NULLABLE(
UIViewController, [tbController.viewControllers objectAtIndex:selectedIndex]) ];
}
}
if ([containerVC isKindOfClass:UISplitViewController.class]) {
Expand All @@ -248,7 +250,8 @@ - (BOOL)isContainerViewController:(UIViewController *)viewController
if ([containerVC isKindOfClass:UIPageViewController.class]) {
UIPageViewController *pageVC = (UIPageViewController *)containerVC;
if (pageVC.viewControllers.count > 0) {
return @[ [[pageVC viewControllers] objectAtIndex:0] ];
return @[ SENTRY_UNWRAP_NULLABLE(
UIViewController, [pageVC.viewControllers objectAtIndex:0]) ];
}
}
return nil;
Expand Down
Loading