From 4340fc464b36c7e6ad6f4fd20d4b42169052c11d Mon Sep 17 00:00:00 2001 From: Nick Dowell Date: Tue, 20 Sep 2022 10:25:19 +0100 Subject: [PATCH 1/2] Mac Catalyst: fix crash in addBreadcrumbForTableViewNotification: --- Bugsnag/Breadcrumbs/BSGNotificationBreadcrumbs.m | 10 +++++----- CHANGELOG.md | 8 ++++++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Bugsnag/Breadcrumbs/BSGNotificationBreadcrumbs.m b/Bugsnag/Breadcrumbs/BSGNotificationBreadcrumbs.m index b210134c9..995f55c0d 100644 --- a/Bugsnag/Breadcrumbs/BSGNotificationBreadcrumbs.m +++ b/Bugsnag/Breadcrumbs/BSGNotificationBreadcrumbs.m @@ -188,12 +188,12 @@ - (instancetype)initWithConfiguration:(BugsnagConfiguration *)configuration } - (NSArray *)automaticBreadcrumbTableItemEvents { -#if !BSG_HAVE_TABLE_VIEW - return @[]; -#elif BSG_HAVE_APPKIT - return @[ NSTableViewSelectionDidChangeNotification ]; +#if TARGET_OS_IOS || TARGET_OS_TV + return @[UITableViewSelectionDidChangeNotification]; +#elif TARGET_OS_OSX + return @[NSTableViewSelectionDidChangeNotification]; #else - return @[ UITableViewSelectionDidChangeNotification ]; + return @[]; #endif } diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b12299a9..1ec716527 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,14 @@ Changelog ========= +## TBD + +### Bug fixes + +* Fix a crash on Mac Catalyst when user interacts with help menu. + [#1484](https://github.com/bugsnag/bugsnag-cocoa/issues/1484) + [#1485](https://github.com/bugsnag/bugsnag-cocoa/pull/1485) + ## 6.23.0 (2022-09-14) ### Enhancements From 22c60b66029dff85d056cb81f025e31644993d6f Mon Sep 17 00:00:00 2001 From: Nick Dowell Date: Tue, 20 Sep 2022 10:31:16 +0100 Subject: [PATCH 2/2] Remove BSG_HAVE_*KIT macros --- .../Breadcrumbs/BSGNotificationBreadcrumbs.m | 36 +++++++------------ Bugsnag/BugsnagSessionTracker.m | 4 +-- Bugsnag/Client/BugsnagClient.m | 2 +- Bugsnag/Helpers/BSGAppKit.h | 2 -- Bugsnag/Helpers/BSGDefines.h | 3 -- Bugsnag/Helpers/BSGUIKit.h | 2 -- .../Source/KSCrash/Recording/BSG_KSCrash.m | 10 +++--- .../BugsnagTests/BugsnagSessionTrackerTest.m | 4 +-- 8 files changed, 23 insertions(+), 40 deletions(-) diff --git a/Bugsnag/Breadcrumbs/BSGNotificationBreadcrumbs.m b/Bugsnag/Breadcrumbs/BSGNotificationBreadcrumbs.m index 995f55c0d..962af8772 100644 --- a/Bugsnag/Breadcrumbs/BSGNotificationBreadcrumbs.m +++ b/Bugsnag/Breadcrumbs/BSGNotificationBreadcrumbs.m @@ -8,16 +8,13 @@ #import "BSGNotificationBreadcrumbs.h" -#import "BugsnagBreadcrumbs.h" -#import "BugsnagConfiguration+Private.h" -#import "BSGKeys.h" -#import "BSGUtils.h" -#import "BSGDefines.h" #import "BSGAppKit.h" +#import "BSGDefines.h" +#import "BSGKeys.h" #import "BSGUIKit.h" - -#define BSG_HAVE_TABLE_VIEW (TARGET_OS_OSX || TARGET_OS_IOS || TARGET_OS_TV) -#define BSG_HAVE_TEXT_CONTROL (TARGET_OS_OSX || TARGET_OS_IOS ) +#import "BSGUtils.h" +#import "BugsnagBreadcrumbs.h" +#import "BugsnagConfiguration+Private.h" BSG_OBJC_DIRECT_MEMBERS @interface BSGNotificationBreadcrumbs () @@ -170,20 +167,20 @@ - (instancetype)initWithConfiguration:(BugsnagConfiguration *)configuration } - (NSArray *)automaticBreadcrumbControlEvents { -#if !BSG_HAVE_TEXT_CONTROL - return nil; -#elif BSG_HAVE_APPKIT - return @[ - NSControlTextDidBeginEditingNotification, - NSControlTextDidEndEditingNotification - ]; -#else +#if TARGET_OS_IOS return @[ UITextFieldTextDidBeginEditingNotification, UITextFieldTextDidEndEditingNotification, UITextViewTextDidBeginEditingNotification, UITextViewTextDidEndEditingNotification ]; +#elif TARGET_OS_OSX + return @[ + NSControlTextDidBeginEditingNotification, + NSControlTextDidEndEditingNotification + ]; +#else + return nil; #endif } @@ -321,8 +318,6 @@ - (BOOL)tryAddSceneNotification:(NSNotification *)notification { #endif - (BOOL)tryAddWindowNotification:(NSNotification *)notification { -#if BSG_HAVE_WINDOW - #if TARGET_OS_IOS || TARGET_OS_TV if ([notification.name hasPrefix:@"UIWindow"] && [notification.object isKindOfClass:UIWINDOW]) { UIWindow *window = notification.object; @@ -365,7 +360,6 @@ - (BOOL)tryAddWindowNotification:(NSNotification *)notification { } #endif -#endif return NO; } @@ -380,8 +374,6 @@ - (void)addBreadcrumbForNotification:(NSNotification *)notification { } - (void)addBreadcrumbForTableViewNotification:(__unused NSNotification *)notification { -#if BSG_HAVE_TABLE_VIEW - #if TARGET_OS_IOS || TARGET_OS_TV NSIndexPath *indexPath = ((UITableView *)notification.object).indexPathForSelectedRow; [self addBreadcrumbWithType:BSGBreadcrumbTypeNavigation forNotificationName:notification.name metadata: @@ -391,8 +383,6 @@ - (void)addBreadcrumbForTableViewNotification:(__unused NSNotification *)notific [self addBreadcrumbWithType:BSGBreadcrumbTypeNavigation forNotificationName:notification.name metadata: tableView ? @{@"selectedRow" : @(tableView.selectedRow), @"selectedColumn" : @(tableView.selectedColumn)} : nil]; #endif - -#endif } - (void)addBreadcrumbForMenuItemNotification:(__unused NSNotification *)notification { diff --git a/Bugsnag/BugsnagSessionTracker.m b/Bugsnag/BugsnagSessionTracker.m index 9162fb399..25579a70e 100644 --- a/Bugsnag/BugsnagSessionTracker.m +++ b/Bugsnag/BugsnagSessionTracker.m @@ -66,7 +66,7 @@ - (void)startWithNotificationCenter:(NSNotificationCenter *)notificationCenter i bsg_log_debug(@"Not starting session because app is not in the foreground"); } -#if BSG_HAVE_APPKIT +#if TARGET_OS_OSX [notificationCenter addObserver:self selector:@selector(handleAppForegroundEvent) name:NSApplicationWillBecomeActiveNotification @@ -81,7 +81,7 @@ - (void)startWithNotificationCenter:(NSNotificationCenter *)notificationCenter i selector:@selector(handleAppBackgroundEvent) name:NSApplicationDidResignActiveNotification object:nil]; -#elif BSG_HAVE_WATCHKIT +#elif TARGET_OS_WATCH [notificationCenter addObserver:self selector:@selector(handleAppForegroundEvent) name:WKApplicationWillEnterForegroundNotification diff --git a/Bugsnag/Client/BugsnagClient.m b/Bugsnag/Client/BugsnagClient.m index 13b8e0a57..d78931ad8 100644 --- a/Bugsnag/Client/BugsnagClient.m +++ b/Bugsnag/Client/BugsnagClient.m @@ -275,7 +275,7 @@ - (void)start { [center addObserver:self selector:@selector(applicationWillTerminate:) -#if BSG_HAVE_APPKIT +#if TARGET_OS_OSX name:NSApplicationWillTerminateNotification #else name:UIApplicationWillTerminateNotification diff --git a/Bugsnag/Helpers/BSGAppKit.h b/Bugsnag/Helpers/BSGAppKit.h index 78da83303..56cd10248 100644 --- a/Bugsnag/Helpers/BSGAppKit.h +++ b/Bugsnag/Helpers/BSGAppKit.h @@ -6,8 +6,6 @@ // Copyright © 2021 Bugsnag Inc. All rights reserved. // -#include "BSGDefines.h" - #if __has_include() #import diff --git a/Bugsnag/Helpers/BSGDefines.h b/Bugsnag/Helpers/BSGDefines.h index 2b37308a4..057304363 100644 --- a/Bugsnag/Helpers/BSGDefines.h +++ b/Bugsnag/Helpers/BSGDefines.h @@ -11,7 +11,6 @@ #include // Capabilities dependent upon system defines and files -#define BSG_HAVE_APPKIT __has_include() #define BSG_HAVE_BATTERY ( TARGET_OS_IOS || TARGET_OS_WATCH) #define BSG_HAVE_MACH_EXCEPTIONS (TARGET_OS_OSX || TARGET_OS_IOS ) #define BSG_HAVE_MACH_THREADS (TARGET_OS_OSX || TARGET_OS_IOS || TARGET_OS_TV ) @@ -22,8 +21,6 @@ #define BSG_HAVE_SIGALTSTACK (TARGET_OS_OSX || TARGET_OS_IOS ) #define BSG_HAVE_SYSCALL (TARGET_OS_OSX || TARGET_OS_IOS || TARGET_OS_TV ) #define BSG_HAVE_UIDEVICE __has_include() -#define BSG_HAVE_UIKIT __has_include() -#define BSG_HAVE_WATCHKIT __has_include() #define BSG_HAVE_WINDOW (TARGET_OS_OSX || TARGET_OS_IOS || TARGET_OS_TV ) // Capabilities dependent upon previously defined capabilities diff --git a/Bugsnag/Helpers/BSGUIKit.h b/Bugsnag/Helpers/BSGUIKit.h index b21e3bcf5..f67aab93d 100644 --- a/Bugsnag/Helpers/BSGUIKit.h +++ b/Bugsnag/Helpers/BSGUIKit.h @@ -6,8 +6,6 @@ // Copyright © 2020 Bugsnag Inc. All rights reserved. // -#import "BSGDefines.h" - #if __has_include() #import diff --git a/Bugsnag/KSCrash/Source/KSCrash/Recording/BSG_KSCrash.m b/Bugsnag/KSCrash/Source/KSCrash/Recording/BSG_KSCrash.m index c792fe42e..c1c5c72bf 100644 --- a/Bugsnag/KSCrash/Source/KSCrash/Recording/BSG_KSCrash.m +++ b/Bugsnag/KSCrash/Source/KSCrash/Recording/BSG_KSCrash.m @@ -26,12 +26,12 @@ #import "BSG_KSCrash.h" -#import "BSG_KSCrashC.h" -#import "BSG_KSCrashIdentifier.h" -#import "BSGDefines.h" #import "BSGAppKit.h" +#import "BSGDefines.h" #import "BSGUIKit.h" #import "BSGWatchKit.h" +#import "BSG_KSCrashC.h" +#import "BSG_KSCrashIdentifier.h" // ============================================================================ #pragma mark - Constants - @@ -71,7 +71,7 @@ - (BSG_KSCrashType)install:(BSG_KSCrashType)crashTypes directory:(NSString *)dir free(recrashReportPath); NSNotificationCenter *nCenter = [NSNotificationCenter defaultCenter]; -#if BSG_HAVE_APPKIT +#if TARGET_OS_OSX // MacOS "active" serves the same purpose as "foreground" in iOS [nCenter addObserver:self selector:@selector(applicationDidEnterBackground) @@ -81,7 +81,7 @@ - (BSG_KSCrashType)install:(BSG_KSCrashType)crashTypes directory:(NSString *)dir selector:@selector(applicationWillEnterForeground) name:NSApplicationDidBecomeActiveNotification object:nil]; -#elif BSG_HAVE_WATCHKIT +#elif TARGET_OS_WATCH [nCenter addObserver:self selector:@selector(applicationDidBecomeActive) name:WKApplicationDidBecomeActiveNotification diff --git a/Tests/BugsnagTests/BugsnagSessionTrackerTest.m b/Tests/BugsnagTests/BugsnagSessionTrackerTest.m index ee3fccebc..016464429 100644 --- a/Tests/BugsnagTests/BugsnagSessionTrackerTest.m +++ b/Tests/BugsnagTests/BugsnagSessionTrackerTest.m @@ -155,9 +155,9 @@ - (void)testHandleAppForegroundEvent { - (void)testStartInBackground { [self.sessionTracker startWithNotificationCenter:NSNotificationCenter.defaultCenter isInForeground:NO]; XCTAssertNil(self.sessionTracker.runningSession, @"There should be no running session after starting tracker in background"); -#if BSG_HAVE_WATCHKIT +#if TARGET_OS_WATCH [NSNotificationCenter.defaultCenter postNotificationName:WKApplicationDidBecomeActiveNotification object:nil]; -#elif BSG_HAVE_APPKIT +#elif TARGET_OS_OSX [NSNotificationCenter.defaultCenter postNotificationName:NSApplicationDidBecomeActiveNotification object:nil]; #else [NSNotificationCenter.defaultCenter postNotificationName:UIApplicationDidBecomeActiveNotification object:nil];