From df9fb5bd6b0bce5f6e1af71bf2635cf40f81eb3e Mon Sep 17 00:00:00 2001 From: Philipp Hofmann Date: Tue, 29 Oct 2024 14:40:12 +0100 Subject: [PATCH] feat: Option for uncaught NSExceptions on macOS (#4471) Add a new option, enableReportingUncaughtExceptions, for reporting uncaught exceptions on macOS. AS SwiftUI applications on macOS can't easily set a Principal class in the Info.plist, especially when using the NSApplicationDelegate, our existing solution of the SentryCrashExceptionApplication doesn't work for them. This new option fixes that problem. --- CHANGELOG.md | 3 +- .../macOS-Swift/macOS-Swift/AppDelegate.swift | 3 +- .../macOS-Swift/Base.lproj/Main.storyboard | 46 ++++++++--- Samples/macOS-Swift/macOS-Swift/CppWrapper.h | 1 + Samples/macOS-Swift/macOS-Swift/CppWrapper.m | 6 ++ Samples/macOS-Swift/macOS-Swift/Info.plist | 2 +- .../macOS-Swift/ViewController.swift | 14 +++- .../macOS-SwiftUI/ContentView.swift | 22 ++++-- .../macOS-SwiftUI/macOS_SwiftUIApp.swift | 1 + Sentry.xcodeproj/project.pbxproj | 18 ++++- SentryTestUtils/ClearTestState.swift | 10 +++ Sources/Sentry/Public/SentryOptions.h | 21 +++++ .../Sentry/SentryCrashExceptionApplication.m | 22 +++--- Sources/Sentry/SentryCrashIntegration.m | 24 +++++- Sources/Sentry/SentryOptions.m | 8 ++ Sources/Sentry/SentryUncaughtNSExceptions.m | 54 +++++++++++++ .../include/SentryUncaughtNSExceptions.h | 27 +++++++ .../SentryCrashIntegrationTests.swift | 72 +++++++++++++++++ .../SentryUncaughtNSExceptionsTests.swift | 77 +++++++++++++++++++ Tests/SentryTests/SentryOptionsTest.m | 7 ++ .../SentryTests/SentryTests-Bridging-Header.h | 1 + 21 files changed, 401 insertions(+), 38 deletions(-) create mode 100644 Sources/Sentry/SentryUncaughtNSExceptions.m create mode 100644 Sources/Sentry/include/SentryUncaughtNSExceptions.h create mode 100644 Tests/SentryTests/Integrations/SentryCrash/SentryUncaughtNSExceptionsTests.swift diff --git a/CHANGELOG.md b/CHANGELOG.md index 34bb1d3c661..e00d5d51809 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,8 +2,9 @@ ## Unreleased -### Fixes +## Feature +- Add option to report uncaught NSExceptions on macOS (#4471) - Build visionOS project with static Sentry SDK (#4462) ### Improvements diff --git a/Samples/macOS-Swift/macOS-Swift/AppDelegate.swift b/Samples/macOS-Swift/macOS-Swift/AppDelegate.swift index dddf3f9484a..cb0965a0655 100644 --- a/Samples/macOS-Swift/macOS-Swift/AppDelegate.swift +++ b/Samples/macOS-Swift/macOS-Swift/AppDelegate.swift @@ -5,8 +5,7 @@ import Sentry class AppDelegate: NSObject, NSApplicationDelegate { func applicationDidFinishLaunching(_ aNotification: Notification) { - UserDefaults.standard.register(defaults: ["NSApplicationCrashOnExceptions": true]) - + // Insert code here to initialize your application SentrySDK.start { options in options.dsn = "https://6cc9bae94def43cab8444a99e0031c28@o447951.ingest.sentry.io/5428557" diff --git a/Samples/macOS-Swift/macOS-Swift/Base.lproj/Main.storyboard b/Samples/macOS-Swift/macOS-Swift/Base.lproj/Main.storyboard index ccb9a21caaf..857c950c921 100644 --- a/Samples/macOS-Swift/macOS-Swift/Base.lproj/Main.storyboard +++ b/Samples/macOS-Swift/macOS-Swift/Base.lproj/Main.storyboard @@ -1,8 +1,8 @@ - + - + @@ -710,10 +710,10 @@ - + + +