From ce15de648de3eaf87375f29382dfb90cd75c2d38 Mon Sep 17 00:00:00 2001 From: Ben Cherry Date: Fri, 2 Feb 2024 15:41:26 -0800 Subject: [PATCH 1/3] Add support for visionOS --- Bugsnag/Breadcrumbs/BSGNotificationBreadcrumbs.m | 2 +- Bugsnag/Helpers/BSGDefines.h | 8 ++++---- Bugsnag/Helpers/BSGRunContext.m | 8 ++++---- .../KSCrash/Source/KSCrash/Recording/BSG_KSSystemInfo.m | 2 ++ 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/Bugsnag/Breadcrumbs/BSGNotificationBreadcrumbs.m b/Bugsnag/Breadcrumbs/BSGNotificationBreadcrumbs.m index 962af8772..8ff03b81b 100644 --- a/Bugsnag/Breadcrumbs/BSGNotificationBreadcrumbs.m +++ b/Bugsnag/Breadcrumbs/BSGNotificationBreadcrumbs.m @@ -318,7 +318,7 @@ - (BOOL)tryAddSceneNotification:(NSNotification *)notification { #endif - (BOOL)tryAddWindowNotification:(NSNotification *)notification { -#if TARGET_OS_IOS || TARGET_OS_TV +#if TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_VISION if ([notification.name hasPrefix:@"UIWindow"] && [notification.object isKindOfClass:UIWINDOW]) { UIWindow *window = notification.object; NSMutableDictionary *metadata = [NSMutableDictionary dictionary]; diff --git a/Bugsnag/Helpers/BSGDefines.h b/Bugsnag/Helpers/BSGDefines.h index 25ac28bf2..4b8a29c95 100644 --- a/Bugsnag/Helpers/BSGDefines.h +++ b/Bugsnag/Helpers/BSGDefines.h @@ -13,15 +13,15 @@ // Capabilities dependent upon system defines and files #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 ) +#define BSG_HAVE_MACH_THREADS (TARGET_OS_OSX || TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_VISION) #define BSG_HAVE_OOM_DETECTION ( TARGET_OS_IOS || TARGET_OS_TV ) && !TARGET_OS_SIMULATOR && !TARGET_OS_MACCATALYST -#define BSG_HAVE_REACHABILITY (TARGET_OS_OSX || TARGET_OS_IOS || TARGET_OS_TV ) +#define BSG_HAVE_REACHABILITY (TARGET_OS_OSX || TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_VISION) #define BSG_HAVE_REACHABILITY_WWAN ( TARGET_OS_IOS || TARGET_OS_TV ) -#define BSG_HAVE_SIGNAL (TARGET_OS_OSX || TARGET_OS_IOS || TARGET_OS_TV ) +#define BSG_HAVE_SIGNAL (TARGET_OS_OSX || TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_VISION) #define BSG_HAVE_SIGALTSTACK (TARGET_OS_OSX || TARGET_OS_IOS ) #define BSG_HAVE_SYSCALL (TARGET_OS_IOS || TARGET_OS_TV ) #define BSG_HAVE_UIDEVICE __has_include() -#define BSG_HAVE_WINDOW (TARGET_OS_OSX || TARGET_OS_IOS || TARGET_OS_TV ) +#define BSG_HAVE_WINDOW (TARGET_OS_OSX || TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_VISION) // Capabilities dependent upon previously defined capabilities #define BSG_HAVE_APP_HANG_DETECTION (BSG_HAVE_MACH_THREADS) diff --git a/Bugsnag/Helpers/BSGRunContext.m b/Bugsnag/Helpers/BSGRunContext.m index 974958b19..f0c045b5c 100644 --- a/Bugsnag/Helpers/BSGRunContext.m +++ b/Bugsnag/Helpers/BSGRunContext.m @@ -40,7 +40,7 @@ static uint64_t GetBootTime(void); static bool GetIsActive(void); static bool GetIsForeground(void); -#if TARGET_OS_IOS || TARGET_OS_TV +#if TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_VISION static UIApplication * GetUIApplication(void); #endif static void InstallTimer(void); @@ -112,7 +112,7 @@ static bool GetIsActive(void) { return GetIsForeground(); #endif -#if TARGET_OS_IOS || TARGET_OS_TV +#if TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_VISION UIApplication *app = GetUIApplication(); return app && app.applicationState == UIApplicationStateActive; #endif @@ -160,7 +160,7 @@ static bool GetIsForeground(void) { } #endif -#if TARGET_OS_IOS || TARGET_OS_TV +#if TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_VISION UIApplication *application = GetUIApplication(); // There will be no UIApplication if UIApplicationMain() has not yet been @@ -195,7 +195,7 @@ static bool GetIsForeground(void) { #endif } -#if TARGET_OS_IOS || TARGET_OS_TV +#if TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_VISION static UIApplication * GetUIApplication(void) { // +sharedApplication is unavailable to app extensions diff --git a/Bugsnag/KSCrash/Source/KSCrash/Recording/BSG_KSSystemInfo.m b/Bugsnag/KSCrash/Source/KSCrash/Recording/BSG_KSSystemInfo.m index b4cb8f570..913435240 100644 --- a/Bugsnag/KSCrash/Source/KSCrash/Recording/BSG_KSSystemInfo.m +++ b/Bugsnag/KSCrash/Source/KSCrash/Recording/BSG_KSSystemInfo.m @@ -319,6 +319,8 @@ + (NSDictionary *)buildSystemInfoStatic { NSString *systemName = @"tvOS"; #elif TARGET_OS_WATCH NSString *systemName = @"watchOS"; +#elif TARGET_OS_VISION + NSString *systemName = @"visionOS"; #endif sysInfo[@BSG_KSSystemField_SystemName] = systemName; From b25b3e5e06332a85965e730dc4709d9826810d36 Mon Sep 17 00:00:00 2001 From: Karl Stenerud Date: Wed, 12 Jun 2024 10:20:00 +0200 Subject: [PATCH 2/3] Source code level visionOS support --- Bugsnag/Helpers/BSGDefines.h | 10 +++++----- Bugsnag/Helpers/BSGHardware.h | 6 +++--- Bugsnag/Helpers/BSGRunContext.m | 8 ++++++++ .../Source/KSCrash/Recording/BSG_KSSystemInfo.m | 2 ++ 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/Bugsnag/Helpers/BSGDefines.h b/Bugsnag/Helpers/BSGDefines.h index 4b8a29c95..a8a0fb1be 100644 --- a/Bugsnag/Helpers/BSGDefines.h +++ b/Bugsnag/Helpers/BSGDefines.h @@ -11,17 +11,17 @@ #include // Capabilities dependent upon system defines and files -#define BSG_HAVE_BATTERY ( TARGET_OS_IOS || TARGET_OS_WATCH) +#define BSG_HAVE_BATTERY ( TARGET_OS_IOS || TARGET_OS_WATCH || TARGET_OS_VISION) #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 || TARGET_OS_VISION) +#define BSG_HAVE_MACH_THREADS (TARGET_OS_OSX || TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_VISION) #define BSG_HAVE_OOM_DETECTION ( TARGET_OS_IOS || TARGET_OS_TV ) && !TARGET_OS_SIMULATOR && !TARGET_OS_MACCATALYST -#define BSG_HAVE_REACHABILITY (TARGET_OS_OSX || TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_VISION) +#define BSG_HAVE_REACHABILITY (TARGET_OS_OSX || TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_VISION) #define BSG_HAVE_REACHABILITY_WWAN ( TARGET_OS_IOS || TARGET_OS_TV ) -#define BSG_HAVE_SIGNAL (TARGET_OS_OSX || TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_VISION) +#define BSG_HAVE_SIGNAL (TARGET_OS_OSX || TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_VISION) #define BSG_HAVE_SIGALTSTACK (TARGET_OS_OSX || TARGET_OS_IOS ) #define BSG_HAVE_SYSCALL (TARGET_OS_IOS || TARGET_OS_TV ) #define BSG_HAVE_UIDEVICE __has_include() -#define BSG_HAVE_WINDOW (TARGET_OS_OSX || TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_VISION) +#define BSG_HAVE_WINDOW (TARGET_OS_OSX || TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_VISION) // Capabilities dependent upon previously defined capabilities #define BSG_HAVE_APP_HANG_DETECTION (BSG_HAVE_MACH_THREADS) diff --git a/Bugsnag/Helpers/BSGHardware.h b/Bugsnag/Helpers/BSGHardware.h index ce3c5b95a..6424e6b84 100644 --- a/Bugsnag/Helpers/BSGHardware.h +++ b/Bugsnag/Helpers/BSGHardware.h @@ -17,7 +17,7 @@ #pragma mark Device -#if TARGET_OS_IOS +#if TARGET_OS_IOS || TARGET_OS_VISION static inline UIDevice *BSGGetDevice(void) { return [UIDEVICE currentDevice]; } @@ -32,7 +32,7 @@ static inline WKInterfaceDevice *BSGGetDevice(void) { #if BSG_HAVE_BATTERY static inline BOOL BSGIsBatteryStateKnown(long battery_state) { -#if TARGET_OS_IOS +#if TARGET_OS_IOS || TARGET_OS_VISION const long state_unknown = UIDeviceBatteryStateUnknown; #elif TARGET_OS_WATCH const long state_unknown = WKInterfaceDeviceBatteryStateUnknown; @@ -41,7 +41,7 @@ static inline BOOL BSGIsBatteryStateKnown(long battery_state) { } static inline BOOL BSGIsBatteryCharging(long battery_state) { -#if TARGET_OS_IOS +#if TARGET_OS_IOS || TARGET_OS_VISION const long state_charging = UIDeviceBatteryStateCharging; #elif TARGET_OS_WATCH const long state_charging = WKInterfaceDeviceBatteryStateCharging; diff --git a/Bugsnag/Helpers/BSGRunContext.m b/Bugsnag/Helpers/BSGRunContext.m index f0c045b5c..58015b685 100644 --- a/Bugsnag/Helpers/BSGRunContext.m +++ b/Bugsnag/Helpers/BSGRunContext.m @@ -128,6 +128,10 @@ static bool GetIsActive(void) { return true; } #endif + +#if TARGET_OS_VISION + return true; +#endif } static bool GetIsForeground(void) { @@ -193,6 +197,10 @@ static bool GetIsForeground(void) { return true; } #endif + +#if TARGET_OS_VISION + return true; +#endif } #if TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_VISION diff --git a/Bugsnag/KSCrash/Source/KSCrash/Recording/BSG_KSSystemInfo.m b/Bugsnag/KSCrash/Source/KSCrash/Recording/BSG_KSSystemInfo.m index 913435240..2d9ba25ab 100644 --- a/Bugsnag/KSCrash/Source/KSCrash/Recording/BSG_KSSystemInfo.m +++ b/Bugsnag/KSCrash/Source/KSCrash/Recording/BSG_KSSystemInfo.m @@ -289,6 +289,8 @@ + (NSDictionary *)buildSystemInfoStatic { sysInfo[@BSG_KSSystemField_SystemName] = @"tvOS"; #elif TARGET_OS_WATCH sysInfo[@BSG_KSSystemField_SystemName] = @"watchOS"; +#elif TARGET_OS_VISION + sysInfo[@BSG_KSSystemField_SystemName] = @"visionOS"; #endif // TARGET_OS_IOS NSDictionary *env = NSProcessInfo.processInfo.environment; From a516f3d1717e2c868e895fcfd04734d1d792d4f4 Mon Sep 17 00:00:00 2001 From: Karl Stenerud Date: Wed, 12 Jun 2024 12:07:01 +0200 Subject: [PATCH 3/3] Add default define for older xcode versions --- Bugsnag/Helpers/BSGDefines.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Bugsnag/Helpers/BSGDefines.h b/Bugsnag/Helpers/BSGDefines.h index a8a0fb1be..729d21bb3 100644 --- a/Bugsnag/Helpers/BSGDefines.h +++ b/Bugsnag/Helpers/BSGDefines.h @@ -10,6 +10,11 @@ #include +#ifndef TARGET_OS_VISION + // For older Xcode that doesn't have VisionOS support... + #define TARGET_OS_VISION 0 +#endif + // Capabilities dependent upon system defines and files #define BSG_HAVE_BATTERY ( TARGET_OS_IOS || TARGET_OS_WATCH || TARGET_OS_VISION) #define BSG_HAVE_MACH_EXCEPTIONS (TARGET_OS_OSX || TARGET_OS_IOS )