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

Fix clearing notifications when the application becomes active instead of when it enters foreground #1451

Merged
merged 5 commits into from
Jun 27, 2024

Conversation

emawby
Copy link
Contributor

@emawby emawby commented Jun 17, 2024

Description

One Line Summary

Fixes a bug where opening the notification center while in the app would clear notifications

Details

The application active state is different than the application foreground state. The app resigns and becomes active if the app is interrupted by the notification center even though it remains in the foreground. We previously were dismissing notifications in didBecomeActive so when the notification center was opened while the app was foregrounded we would dismiss notifications.

There also seems to be an apple bug where the resign and become active triggers would fire twice as you are swiping down the notification center. This means that we were dismissing the notifications as you open the notification center which made the problem even worse.

I refactored where we handle notifications related tasks in response to application lifecycle events. The OSNotificationsManager now registers itself to listen to the lifecycle and handles changes on the foreground event.
I also moved checking if the app is using UIScenes to OneSignalCore.

Motivation

bug fix

Scope

notifications and application lifecycle

Testing

Unit testing

Created a new unit testing target for OneSignalNotifications and added it to the UnitTestApp target.

  • Added 3 simple tests related to listening to foregrounding the app

Manual testing

  • Tested backgrounding and foregrounding with and without notifications with badges
  • Tested changing the permission value in the background and then foregrounding
  • Tested resigning and regaining active using the notification center while the the app was foregrounded

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
    • If it is hard to explain how any codes changes are related to each other then it most likely needs to be more than one PR
  • 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.
    • Simplify with less code, followed by splitting up code into well named functions and variables, followed by adding comments to the code.
  • I have reviewed this PR myself, ensuring it meets each checklist item
    • WIP (Work In Progress) is ok, but explain what is still in progress and what you would like feedback on. Start the PR title with "WIP" to indicate this.

This change is Reviewable

The application active state is different than the application foreground state. The app resigns and becomes active if the app is interrupted by the notification center even though it remains in the foreground. We previously were dismissing notifications in didBecomeActive so when the notification center was opened while the app was foregrounded we would dismiss notifications.

There also seems to be an apple bug where the resign and become active triggers would fire twice as you are swiping down the notification center. This means that we were dismissing the notifications as you open the notification center which made the problem even worse.
Move uiscene check to core in a bundle utils file
Create stub unit testing file for notifications
@emawby emawby force-pushed the fix/clearing_notifs_when_swiping_notif_center branch 2 times, most recently from 6883980 to 1a4b1a9 Compare June 20, 2024 22:36
@emawby emawby changed the title [WiP]Fix clearing notifications when the application becomes active instead of when it enters foreground Fix clearing notifications when the application becomes active instead of when it enters foreground Jun 20, 2024
@emawby emawby requested a review from nan-li June 20, 2024 22:40
@emawby emawby force-pushed the fix/clearing_notifs_when_swiping_notif_center branch from 1a4b1a9 to 899541c Compare June 20, 2024 22:49
OneSignalCoreMocks.resignActive()
// App becomes active the app
OneSignalCoreMocks.becomeActive()
// Ensure that badge count == 0
Copy link
Contributor

Choose a reason for hiding this comment

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

nit, this comment should say "count == 1"?

@@ -0,0 +1,11 @@
//
// OSBundleUtils.h
// OneSignal
Copy link
Contributor

Choose a reason for hiding this comment

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

The new files created can clean up the headers?

@emawby emawby requested a review from nan-li June 26, 2024 19:07
@emawby emawby merged commit f1489cc into main Jun 27, 2024
4 of 5 checks passed
@emawby emawby deleted the fix/clearing_notifs_when_swiping_notif_center branch June 27, 2024 18:04
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.

2 participants