OneSignal / OneSignal-iOS-SDK

OneSignal is a free push notification service for mobile apps. This plugin makes it easy to integrate your native iOS app with OneSignal. https://onesignal.com
Other
496 stars 263 forks source link

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

Closed emawby closed 4 months ago

emawby commented 5 months ago

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.

Manual testing

Affected code checklist

Checklist

Overview

Testing

Final pass


This change is Reviewable