-
-
Notifications
You must be signed in to change notification settings - Fork 371
fix: Remove extra @objc from SessionTracker #6993
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,7 @@ typealias Application = NSApplication | |
|
|
||
| /// Tracks sessions for release health. For more info see: | ||
| /// https://docs.sentry.io/workflow/releases/health/#session | ||
| @_spi(Private) @objc(SentrySessionTracker) public final class SessionTracker: NSObject { | ||
| final class SessionTracker { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Removing NSObject breaks NotificationCenter selector-based observationThe |
||
|
|
||
| // MARK: Private | ||
|
|
||
|
|
@@ -39,9 +39,9 @@ typealias Application = NSApplication | |
| self.notificationCenter.removeObserver(self, name: nil, object: nil) | ||
| } | ||
|
|
||
| // MARK: Public | ||
| // MARK: Internal | ||
|
|
||
| @objc public func start() { | ||
| func start() { | ||
| // We don't want to use WillEnterForeground because tvOS doesn't call it when it launches an app | ||
| // the first time. It only calls it when the app was open and the user navigates back to it. | ||
| // DidEnterBackground is called when the app launches a background task so we would need to | ||
|
|
@@ -73,7 +73,7 @@ typealias Application = NSApplication | |
| #endif | ||
| } | ||
|
|
||
| @objc public func stop() { | ||
| func stop() { | ||
| SentrySDKInternal.currentHub().endSession() | ||
|
|
||
| removeObservers() | ||
|
|
@@ -83,7 +83,7 @@ typealias Application = NSApplication | |
| wasStartSessionCalled = false | ||
| } | ||
|
|
||
| @objc public func removeObservers() { | ||
| func removeObservers() { | ||
| #if ((os(iOS) || os(tvOS) || (swift(>=5.9) && os(visionOS))) && !SENTRY_NO_UIKIT) || ((os(macOS) || targetEnvironment(macCatalyst)) && !SENTRY_NO_UIKIT) | ||
| // Remove the observers with the most specific detail possible, see | ||
| // https://developer.apple.com/documentation/foundation/nsnotificationcenter/1413994-removeobserver | ||
|
|
@@ -94,8 +94,6 @@ typealias Application = NSApplication | |
| #endif | ||
| } | ||
|
|
||
| // MARK: Internal | ||
|
|
||
| let options: Options | ||
| let dateProvider: SentryCurrentDateProvider | ||
| let notificationCenter: SentryNSNotificationCenterWrapper | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Observer removal fails for non-NSObject observers in test utility
The
Observer.observerWithObjectcase was changed to useWeakReference<AnyObject>to support non-NSObject observers, but theremoveObservermethod's comparison logic at line 85 still usesobserver as? NSObject. For non-NSObject observers, this cast returnsnil, causing the identity comparisonweakObserver.value === observer as? NSObjectto fail, so observers won't be properly removed. The comparison should useobserver as AnyObjectinstead.