OneSignal / OneSignal-Cordova-SDK

OneSignal is a free push notification service for mobile apps. This plugin makes it easy to integrate your Ionic, PhoneGap CLI, PhoneGap Build, Cordova, or Sencha Touch app with OneSignal. Supports Android, iOS, and Amazon's Fire OS platforms. https://onesignal.com
Other
250 stars 197 forks source link

iOS Badge Count Not Reset #455

Closed SamJWeissman closed 4 years ago

SamJWeissman commented 5 years ago

Description:

Push notifications and incrementing of the badge count all work perfectly. Unfortunately, while the badge is "cleared", when a new notification comes through, it resumes with the previous badge count rather than starting from 0.

Environment

  1. What version of the Cordova SDK are you using? Cordova 8.1.2, OneSignal 2.4.5, XCode 9
  2. Provide a list of your project dependencies (using cordova plugin list or copy-pasting your config.xml)

cordova-plugin-hockeyapp 5.1.2 onesignal-cordova-plugin 2.4.5 ccordova-plugin-splashscreen 5.0.2 cordova-plugin-device 2.0.2 cordova-plugin-whitelist 1.3.3 cordova plugin-wkwebview-engine 1.1.4 corova-plugin-wkwebview-file-xhr 2.1.1 cordova-plugin-inappbrowser 3.0.0 cordova-plugin-web-share 1.1.0 cordova-plugin-network-information 2.0.1

ios engine 4.5.5

Steps to Reproduce Issue:

  1. Add the onesignal-cordova-plugin to your project
  2. Initialize the plugin with your app ID
  3. Attempt to receive a push notification
  4. Badge count bumps to 1.
  5. Open app, clearing the iOS badge
  6. Attempt to receive a push notification
  7. Badge count bumps to 2, but should be 1 again after having been "cleared"

Note: Not sure if this is relevant. The .ipa is currently being downloaded from HockeyApp. We've pushed/downloaded several versions throughout the development phase ( we're still waiting for review from Apple ). I'm not sure if that would make any difference in the issue we're seeing.

Can confirm that this issue is seen when downloading from the App Store as well

karltaylor commented 4 years ago

Does the group string have to be exactly the same as the bundle id?

My issue:

My string is <string>group.com.{company}.oneSignal</string>

But my bundle id's are as follow

com.{company}.{whitelabelAppName}.{env}

Would I have to create groups that are explicitly the same as the bundle id?

Update:

I had to set the OneSignal_app_groups_key inside my app info.plist and the OneSignalNotificationServiceExtension/info.plist and it worked 🙂

rgomezp commented 4 years ago

See previous comments for solution

pecen commented 4 years ago

Like several have pointed out, follow the instructions for setting up an App Group. At least that worked for me. The following is from the OneSignal documentation:

  1. Add App Groups (Optional but Recommended) In order for your application to be able to let push notifications increment/decrement the badge count, you need to set up an App Group for your application.

Please follow this guide to set up a OneSignal app group in your app.

lutluthfi commented 3 years ago

OneSignal_app_groups_key

yo @karltaylor , what string did you give for OneSignal_app_groups_key in Info.plist and OneSignalNotificationExtensionService/Info.plist? because I see you have this format com.{company}.{whitelabelAppName}.{env} for bundle id. Like the OneSignal default one com.{company}.{whitelabelAppName}.{env}.onesignal or just your bundle id com.{company}.{whitelabelAppName}.{env}?

fikkatra commented 3 years ago

@rgomezp after following instructions from the documentation and this page, I can confirm this problem still occurs. Using v2.11.1; Not using the badge plugin.

Main Target (the 'l' of 'onesignal' is cut off by XCode, but I double checked, it is definitely there): image

OneSignalNotificationServiceExtension Target: image

Main app entitlement file: image

OneSignalNotifcationServiceExtension entitlement file: image

Main app info.plist: image

OneSignalNotifcationServiceExtension info.plist: image

The following behaviour occurs:

I haven't set OneSignal_disable_badge_clearing because I want the badge to be automatically cleared when the app is opened.

Did I miss anything?

pleymor commented 2 years ago

We had a problem which lokoed like 2 different counters on our IOS app: When the app set the number of badges, this number appeared well on the app badge.

But out of the app, when OneSignal sent a notification (with ios_badgeType: 'Increase' and ios_badgeCount: 1), the badge number restarted from 1 (and increased by 1 at each push notification).

Finally, the problem was a wrong App group set in XCode. As soon as we changed it to be group.EXACT_BUNDLE.onesignal, it worked :)

Hope it can help.

Harika-mob commented 8 months ago

Hi @@chagaspac , In IOS, we are unable to reset the badge number when we click the pushwoosh notification Would you be able to fix this?