OneSignal / OneSignal-Unity-SDK

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

[Bug]: Badge Counter not resetting properly #527

Open gadzilka opened 2 years ago

gadzilka commented 2 years ago

What happened?

After the badge counter is reset to 0 and a new push notification received with +1 on the badge, the old value is restored. Many of our customers report this issue to us from different apps.

Steps to reproduce?

1. Launch the app - bagde: 0
2. Receive a new push notification with +1 - bagde: 1
3. Receive a new push notification with +1 - badge: 2
4. Open the app - badge: 0
5. Receive a new push notification with +1 - badge: 3

What did you expect to happen?

Unfortunately, there are not many places in your code that can be debbuged. I tried to get more information from your Notification Extension.

In Step 5 before calling OneSignal.didReceiveNotificationExtensionRequest: onesignalBadgeCount is 0 (this is the value from UserDefault associated with the app group) bestAttemptContent.badge is 3 (the content of UNNotificationRequest) after calling OneSignal.didReceiveNotificationExtensionRequest onesignalBadgeCount is 3 (the badge counter also has the same value)

This means that your server send the wrong number for the badge counter. I can assume that something wrong happened in the app when you reset the badge counter and send the information to your server.

Unity version

Unity 2020.3.36f1

OneSignal Unity SDK version

3.0.3

Platform

iOS

Relevant log output

No response

Code of Conduct

jkasten2 commented 2 years ago

@gadzilka Thanks for reporting and digging in and providing these debugging details.

It seems the Notification Service Extension is running correctly as you were able to get debugging output from it.

In Step 5 before calling OneSignal.didReceiveNotificationExtensionRequest: onesignalBadgeCount is 0 (this is the value from UserDefault associated with the app group)

Was this value also 0 on step 3 from above as well?

When did you create your app on the OneSignal dashboard? The defaults for badges are different if it was created in 2018 vs something newer.

gadzilka commented 2 years ago

Was this value also 0 on step 3 from above as well?

No, in step 3, after calling OneSignal.didReceiveNotificationExtensionRequest the value of onesignalBadgeCount is 2. Only 2 push notifications have been received so far.

When did you create your app on the OneSignal dashboard? The defaults for badges are different if it was created in 2018 vs something newer.

It was old app, it was created a long time ago. Should I test a new one? What to do with the old one?

Here are some additional logs from the main app in step 4 (user id and app id are hidden in logs):

applicationWillEnterForeground: onesignalBadgeCount is 2
applicationDidBecomeActive: onesignalBadgeCount is 2
DEBUG: OneSignal SessionManager attemptSessionUpgrade with entryAction: 1
DEBUG: OneSignal SessionManager attemptSessionUpgrade try UNATTRIBUTED to INDIRECT upgrade
DEBUG: OneSignal SessionManager sendSessionEndingWithInfluences with influences: ()
VERBOSE: HTTP Request (OSRequestBadgeCount) with URL: https://api.onesignal.com/players/<user id>, with parameters: {
  "app_id" : "<app id>",
  "badgeCount" : 0
}
applicationWillResignActive: onesignalBadgeCount is 0
sainecy commented 3 weeks ago

@gadzilka @jkasten2

I encountered the same issue in a native iOS app without using Unity. The problem stemmed from incorrect app group configuration. To resolve this, ensure that you're using the recommended app group, which should be added to both the OneSignalNotificationServiceExtension and the main target of your app.

If you're using a custom name for your app group instead of the recommended one, make sure this is reflected in the info.plist files for both targets. For more details, refer to OneSignal's documentation under the "Optional instructions to setup custom App Group Name" section here.