OneSignal / react-native-onesignal

React Native Library for OneSignal Push Notifications Service
Other
1.57k stars 373 forks source link

[Bug]: addSubscriptionObserver not firing on app returning to foreground after notification permission change #1478

Closed jon-eubank closed 5 months ago

jon-eubank commented 1 year ago

What happened?

The "addSubscriptionObserver" event handler does not get triggered when the user sends the app to the background, changes notification permissions, and then brings the app back to the foreground. It fires in the same situation on Android devices though.

To get the subscription change event to actually fire, the app must be closed, then user waits 30-60s, then app is reopened.

Steps to reproduce?

1) Install version 4.4.1 of the SDK
2) Start the application
3) Send application to the background
4) Open up settings for the app and modify the notification permissions (enable-->disable or reverse)
5) Bring app back to the foreground
6) The addSubscriptionObserver fails to fire, even though the subscription status is updated on OneSignal's site

What did you expect to happen?

I expected the event to fire because the subscription status has been modified, as it does on Android devices. OneSignal's user record gets updated correctly on their website, but the subscription change event never triggers.

React Native OneSignal SDK version

Release 4.4.1

Which platform(s) are affected?

Relevant log output

No response

Code of Conduct

brismithers commented 1 year ago

@jde8aa can you confirm whether you see this issue on a real iOS device? If this is on an iOS simulator, I would say this is currently expected due to the iOS simulator not having full support for push notifications.

jon-eubank commented 1 year ago

@brismithers Hi Brian, thanks for the reply. Yes, this is currently happening on a real iOS device and not being tested using a simulator. If I background the app, disable notifications, wait 60 seconds (as OneSignal support directed me to do due to a "cooldown time"), and then bring the app back up the event handler is not triggered.

Interestingly enough though the addPermissionObserver handler does fire, and OneSignal updates the user on the GUI of their site to accurately reflect the permissions change.

Additionally, if I completely exit the app, change notification permissions, wait 60s, and then open the app the handler will fire correctly.

brismithers commented 1 year ago

@jde8aa unfortunately not able to reproduce this. Deploying the example app to a real device and following the instructions provided I am seeing the appropriate subscription observer being called.

Are you able to share your full log showing the OneSignal SDK initialization as well as the flipping of the notification permission? You can also email the log to support@onesignal.com and reference this GitHub issue.

Thanks!

jacklj commented 1 year ago

I'm seeing this issue, on iOS Simulator only. Also, getDeviceState() always gives notificationPermissionStatus: 3 and hasNotificationPermission: true, whatever the actual permissions state.

Version: 4.5.0 iOS Simulator (iPhone 14)

brismithers commented 1 year ago

@jacklj this is currently expected on the simulator, due to push notification limitations on the simulator for iOS. Although I'll paste the XCode 14 release notes, if you fall into this category and are seeing the issue on the simulator let us know!

Simulator now supports remote notifications in iOS 16 when running in macOS 13 on Mac computers with Apple silicon or T2 processors. Simulator supports the Apple Push Notification Service Sandbox environment. Your server can send a remote notification to your app running in that simulator by connecting to the APNS Sandbox (api.sandbox.push.apple.com). Each simulator generates registration tokens unique to the combination of that simulator and the Mac hardware it’s running on. See User Notifications for more information.