[PLAT-7208] Fix missing sessions when started in background state #1180
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Goal
Fix a regression (introduced in release v6.9.5 by #1108) where the session was not captured at launch if Bugsnag was started before
willFinishLaunchingWithOptions
in iOS apps that do not adopt the UIScene life-cycle.Overview
If Bugsnag is started early in the app life-cycle, before the app delegate's
willFinishLaunchingWithOptions
method is called, thenapplicationState
is reported as.background
and Bugsnag does not start a session.In iOS apps that do not adopt the
UIScene
life-cycle, nowillEnterForegroundNotification
is posted during launch and consequently no session was being started until the app was resumed from the background state. AdidBecomeActiveNotification
is posted during launch.Changeset
The session tracker now starts a session in response to
didBecomeActiveNotification
as well aswillEnterForegroundNotification
.Notification registration logic has been moved to
BugsnagSessionTracker
to make it more testable.Testing
Reproduced the issue and verified the fix using a test app.
Added unit test cases to verify that
UIApplicationDidBecomeActiveNotification
alonehandleAppForegroundEvent
do not result in multiple sessionsE2E tests cannot test this because the fixture app cannot start Bugsnag early enough in the app's life-cycle.