-
-
Notifications
You must be signed in to change notification settings - Fork 372
Flush Logs on WillTerminate or WillResignActive App State
#6909
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
be66378
fd55fdf
115a625
71f478e
162273e
3f4813d
aa1fbc9
6cdd1b0
8e36044
d502009
d22d16e
539d652
e214d5e
b493f18
13de622
e270fa1
19df878
0f74c74
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 |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| @_implementationOnly import _SentryPrivate | ||
|
|
||
| #if (os(iOS) || os(tvOS) || (swift(>=5.9) && os(visionOS))) && !SENTRY_NO_UIKIT | ||
| import UIKit | ||
| private typealias CrossPlatformApplication = UIApplication | ||
| #elseif (os(macOS) || targetEnvironment(macCatalyst)) && !SENTRY_NO_UIKIT | ||
| import AppKit | ||
| private typealias CrossPlatformApplication = NSApplication | ||
| #endif | ||
|
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: Mac Catalyst incorrectly imports AppKit instead of UIKitThe conditional compilation directives incorrectly import |
||
|
|
||
| #if ((os(iOS) || os(tvOS) || (swift(>=5.9) && os(visionOS))) && !SENTRY_NO_UIKIT) || ((os(macOS) || targetEnvironment(macCatalyst)) && !SENTRY_NO_UIKIT) | ||
|
|
||
| protocol NotificationCenterProvider { | ||
| var notificationCenterWrapper: SentryNSNotificationCenterWrapper { get } | ||
| } | ||
|
|
||
| final class FlushLogsIntegration<Dependencies: NotificationCenterProvider>: NSObject, SwiftIntegration { | ||
|
|
||
| private let notificationCenter: SentryNSNotificationCenterWrapper | ||
|
|
||
| init?(with options: Options, dependencies: Dependencies) { | ||
| guard options.enableLogs else { | ||
| return nil | ||
| } | ||
|
|
||
| self.notificationCenter = dependencies.notificationCenterWrapper | ||
|
|
||
| super.init() | ||
|
|
||
| notificationCenter.addObserver( | ||
| self, | ||
| selector: #selector(willResignActive), | ||
| name: CrossPlatformApplication.willResignActiveNotification, | ||
| object: nil | ||
| ) | ||
|
|
||
| notificationCenter.addObserver( | ||
| self, | ||
| selector: #selector(willTerminate), | ||
| name: CrossPlatformApplication.willTerminateNotification, | ||
| object: nil | ||
| ) | ||
| } | ||
|
|
||
| func uninstall() { | ||
| notificationCenter.removeObserver( | ||
| self, | ||
| name: CrossPlatformApplication.willResignActiveNotification, | ||
| object: nil | ||
| ) | ||
|
|
||
| notificationCenter.removeObserver( | ||
| self, | ||
| name: CrossPlatformApplication.willTerminateNotification, | ||
| object: nil | ||
| ) | ||
| } | ||
|
|
||
| deinit { | ||
| uninstall() | ||
| } | ||
|
|
||
| @objc private func willResignActive() { | ||
| guard let client = SentrySDKInternal.currentHub().getClient() else { | ||
| return | ||
| } | ||
| client.captureLogs() | ||
| } | ||
|
|
||
| @objc private func willTerminate() { | ||
| guard let client = SentrySDKInternal.currentHub().getClient() else { | ||
| return | ||
| } | ||
| client.captureLogs() | ||
| } | ||
|
|
||
| static var name: String { | ||
| "FlushLogsIntegration" | ||
| } | ||
| } | ||
|
|
||
| #endif | ||
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.
## 9.0.0.Consider moving the entry to the
## Unreleasedsection, please.