getsentry / sentry-cocoa

The official Sentry SDK for iOS, tvOS, macOS, watchOS.
https://sentry.io/for/cocoa/
MIT License
773 stars 306 forks source link

Sentry registers own NSApplication subclass (8.26 regression) #3992

Closed triplef closed 2 weeks ago

triplef commented 2 weeks ago

Platform

macOS

Environment

Production, Develop, TestFlight

Installed

Swift Package Manager

Version

8.26

Xcode Version

15.4

Did it work on previous versions?

8.25

Steps to Reproduce

Since 8.26 it is no longer possible to use a custom NSApplication subclass while initializing Sentry before that class is initialized, because Sentry calls [SentryCrashExceptionApplication sharedApplication] as part of its initialization and thereby registers SentryCrashExceptionApplication as NSApplication instance.

This was caused by #3957. The fix is to e.g. have Sentry call [SentryCrashExceptionApplication class] instead.

  1. Create custom NSApplication subclass inheriting from SentryCrashExceptionApplicationregister it as "Principal class" in Info.plist
  2. Initialize SentrySDK before application class is initialized (e.g. from +initialize)

Expected Result

NSApplication subclass is initialized normally.

Actual Result

SentryCrashExceptionApplication is registered as application instance.

Demo project

The following project illustrates the issue. Notice how [MyApplication init] is never called, even tho MyApplication is registered as principal class. SentryApplicationTest.zip

Are you willing to submit a PR?

yes