Update backgrounded logic to determine displaying cached IAMs #1233
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.
Description
One Line Summary
Don't display cached IAMs if app returns from an inactive state (and did not enter the background), but keep all other behavior the same.
Details
Motivation
What Was Happening?
When the app is foregrounded and it is not a new session, the SDK initializes IAMs from cache. Any IAM with the trigger "on app open" will display. This can be triggered when a native dialog like notification permission prompt displays over the app and is then dismissed, or the app goes into an inactive "peekaboo" state and returns without entering the background.
An issue was reported for push pre-prompt IAMs that have the "on app open" trigger. After the IAM displays, the native permission dialog displays. After the user makes a selection and the dialog is dismissed, the original IAM will display once again (as the app is considered to return to the foreground). See video.
Upload.from.GitHub.for.iOS.MOV
After discussions and seeing that Android behaves differently, we decided to keep this behavior to show "on app open" IAMs every time app is foregrounded as is but change the behavior for the major release 5.x.x. However, we should distinguish between the following 2 flows:
application will resign active → application did become active (in this case, app is not actually backgrounded, it may be that a native prompt displayed over the app) 👈🏼 this leads to the bug in the video and this PR will change this behavior
will resign active → did enter background → will enter foreground → did become active 👈🏼 no behavior change
Scope
willResignActiveTriggered
anddidEnterBackgroundTriggered
to track if an app was actually backgrounded or just inactive.Testing
Unit testing
None added
Manual testing
Tested on iPhone 13 with iOS 16
Affected code checklist
Checklist
Overview
Testing
Final pass
This change is