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

Update backgrounded logic to determine displaying cached IAMs #1233

Merged
merged 1 commit into from
Mar 15, 2023

Conversation

nan-li
Copy link
Contributor

@nan-li nan-li commented Feb 28, 2023

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:

  1. 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

  2. will resign active → did enter background → will enter foreground → did become active 👈🏼 no behavior change

Scope

  • Add app backgrounded vs app inactive detection by adding 2 state flags willResignActiveTriggered and didEnterBackgroundTriggered to track if an app was actually backgrounded or just inactive.
  • We will consider the application truly backgrounded if the states are anything except:
willResignActiveTriggered = TRUE && didEnterBackgroundTriggered = FALSE
  • Use backgrounded logic to determine if we should display cached IAMs, as we won't if the app was simply inactive.
  • I had considered and tested out other options, but this PR makes the minimal amount of behavior changes, as there is a lot of existing logic that I don't want to mess around with.

Testing

Unit testing

None added

Manual testing

Tested on iPhone 13 with iOS 16

  • starting app from killed state
  • foregrounding app leading to a new session
  • putting the app into a "peekaboo" inactive state and returning
  • displaying native dialogs over the app
  • setting privacy consent needed and granted

Affected code checklist

  • Notifications
    • Display
    • Open
    • Push Processing
    • Confirm Deliveries
  • Outcomes
  • Sessions
  • In-App Messaging
  • REST API requests
  • Public API changes

Checklist

Overview

  • I have filled out all REQUIRED sections above
  • PR does one thing
  • Any Public API changes are explained in the PR details and conform to existing APIs

Testing

  • I have included test coverage for these changes, or explained why they are not needed
  • All automated tests pass, or I explained why that is not possible
  • I have personally tested this on my device, or explained why that is not possible

Final pass

  • Code is as readable as possible.
  • I have reviewed this PR myself, ensuring it meets each checklist item

This change is Reviewable

* Add app backgrounded vs app inactive detection by adding 2 state flags `willResignActiveTriggered` and `didEnterBackgroundTriggered` to track if an app was actually backgrounded or just inactive.
* We will consider the application truly backgrounded if the states are anything except:
- willResignActiveTriggered = TRUE && didEnterBackgroundTriggered = FALSE
* Use backgrounded logic to determine if we should display cached IAMs, as we won't if the app was simply inactive.
* This makes the minimal amount of behavior changes, as there is a lot of existing logic that I don't want to mess around with
@nan-li nan-li force-pushed the fix/foregrounding_detection branch from c06fc5e to 579c0de Compare March 7, 2023 00:29
@nan-li nan-li changed the title [wip] use backgrounded logic to determine displaying cached IAMs Update backgrounded logic to determine displaying cached IAMs Mar 7, 2023
@jennantilla
Copy link
Contributor

Nice workaround with state flags to evaluate whether the app actually entered the background or not!

How will the behavior change for the major release 5.x.x.?

Copy link
Contributor

@emawby emawby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 3 of 3 files at r1, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @brismithers, @fhboswell, @jennantilla, and @jkasten2)

@nan-li
Copy link
Contributor Author

nan-li commented Mar 15, 2023

How will the behavior change for the major release 5.x.x.?

For major release 5.x.x, we will only displays IAMs from cache on a new session (potentially as we pull IAMs on new session too), so we don't have this same issue. The "on app open" trigger will be effectively be on app cold start or after the app is backgrounded for 30 seconds.

@nan-li nan-li merged commit 933933e into main Mar 15, 2023
@nan-li nan-li deleted the fix/foregrounding_detection branch March 15, 2023 20:10
@emawby emawby mentioned this pull request Mar 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants