Skip to content
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

[PLAT-6614] Stop session being reported if app is launched in the background #1108

Merged
merged 1 commit into from
Jun 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Bugsnag/BugsnagSessionTracker.m
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ - (void)handleAppBackgroundEvent {
}

- (void)handleAppForegroundEvent {
if (self.backgroundStartTime
&& [[NSDate date] timeIntervalSinceDate:self.backgroundStartTime] >= BSGNewSessionBackgroundDuration) {
if (!self.currentSession ||
(self.backgroundStartTime && [[NSDate date] timeIntervalSinceDate:self.backgroundStartTime] >= BSGNewSessionBackgroundDuration)) {
[self startNewSessionIfAutoCaptureEnabled];
}
self.backgroundStartTime = nil;
Expand Down
8 changes: 5 additions & 3 deletions Bugsnag/Client/BugsnagClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -403,13 +403,15 @@ - (void)start {

self.started = YES;

[self.sessionTracker startNewSessionIfAutoCaptureEnabled];
if (bsg_kscrashstate_currentState()->applicationIsInForeground) {
[self.sessionTracker startNewSessionIfAutoCaptureEnabled];
} else {
bsg_log_debug(@"Not starting session because app is not in the foreground");
}

// Record a "Bugsnag Loaded" message
[self addAutoBreadcrumbOfType:BSGBreadcrumbTypeState withMessage:@"Bugsnag loaded" andMetadata:nil];

// notification not received in time on initial startup, so trigger manually
[self willEnterForeground:self];
[self.pluginClient loadPlugins];

if (self.configuration.launchDurationMillis > 0) {
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ Changelog

### Bug fixes

* Stop session being reported if app is launched in the background.
[#1107](https://github.com/bugsnag/bugsnag-cocoa/pull/1107)

* Fix KSCrash state storage for apps with no CFBundleName.
[#1103](https://github.com/bugsnag/bugsnag-cocoa/pull/1103)

Expand Down