OneSignal / react-native-onesignal

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

ios badge does not reset #309

Closed jjdp closed 6 years ago

jjdp commented 7 years ago

It does not reset when you launch the app. The only time it resets is if the app is in the foreground while you receive a notification. It may have to do with the in app behavior.

self.oneSignal = [[RCTOneSignal alloc] initWithLaunchOptions:launchOptions
                                                         appId:@""
                                                         settings:@{kOSSettingsKeyInFocusDisplayOption : @(OSNotificationDisplayTypeNone), kOSSettingsKeyAutoPrompt : @YES}];

Tested with the following:

  1. Send two test notifs with increasing badge to 1
  2. App receives notif in background then it sets the badge to 2.
  3. Launch the app. Badge gets cleared in the app icon.
  4. Close or background the app and do step 1 again.
  5. Badge counter is now 4
Nightsd01 commented 6 years ago

@jjdp closing this issue due to inactivity.

You can control this behavior using the OneSignal_disable_badge_clearing boolean setting in Info.plist.

Please feel free to respond if you are still encountering this issue and I will be happy to reopen and investigate.

scottmas commented 6 years ago

This is exactly what is happening to me. I'm up to 70 notification count thus far. I have not fiddled with any of the default settings.

Based on your response Nightsd01, I think you may have misunderstood somewhat. The notification count goes away once you open the app. But then once you receive another notification, it keeps incrementing from where you left off.

I think it's an issue with the http api potentially. When the app initializes, I think a request should be sent to OneSignal telling it to edit the device and return the device's notification count back to 0. I think since that is not happening, the server sdk simply thinks the device is still at the old badge count. SettingOneSignal_disable_badge_clearing just deals with local behavior.

Nightsd01 commented 6 years ago

@scottmas I am guessing you created your app within the last week?

If so, we recently switched iOS badge count logic to happening on the device instead of our backend.

The solution in your case is to add an App Group to your app & extension service (also add the extension service if you haven't done that yet). This will result in a more consistent badge count since the count is being maintained on the device directly.

Please read our docs: https://documentation.onesignal.com/docs/ios-sdk-app-groups-setup

cojo commented 6 years ago

@Nightsd01 I am just now integrating OneSignal React Native into our app today, and I am seeing this same issue despite having created and hooked up both the App Group and Extension Service according to the instructions in the documentation.

Are there any other steps we can take to debug this / check what else might be going wrong here? I've tried doing this manually as well:

- (void)applicationDidBecomeActive:(UIApplication *)application
{
  [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
}

But it has the same effect we were already seeing: the icon clears when the app is opened or the notification is clicked, but on the next notification the count is incremented by 1 without being reset (i.e. it goes from 4 -> 0 -> 5).

jkasten2 commented 6 years ago

@cojo I recommend contacting OneSignal support while logged into the dashboard. They can check your app on your account to make sure the new badge increment logic is turned on for it.

Nightsd01 commented 6 years ago

@cojo this does mean that either the app group or the extension service aren’t configured correctly. Here are some troubleshooting steps:

  1. When did you create the app on OneSignal’s dashboard? Within the last 3 weeks? If not, it’s using server-side badge logic. Unfortunately, this means that when you manually set the badge count yourself (using setApplicationIconBadgeNumber), it won’t be reflected in our server so it will get reset the next time the user gets a push from us.

  2. If so, please make sure that the name of your app group is correct. It should be group.(your main app’s bundle id).onesignal

  3. Make sure the extension service is configured correctly by sending rich push notifications, for example with an image attachment. Does the image show up? If not, you’ll want to make sure that the Deployment Target in the extension service matches your main app (but must be at least iOS 10 or higher)

peterkuiper commented 6 years ago

We are having the same issue. Rich push notifications work fine. We did create the app recently. Did you get this fixed @cojo?

cojo commented 6 years ago

Unfortunately I have not had a chance to try sending a rich push notification for our app / confirm if those are working since I last posted here. We did create it within a few days of that post though so it theoretically should be falling under the new logic.

I also confirmed the app group matches re suggestion 2. I think we might not have yet targeted iOS 10 at that time (we were targeting 9) but we are targeting 10 now.

I'll update here next time we have a chance to confirm if it's still broken for us.

scottmas commented 6 years ago

Can confirm this is broken for us. I get rich images just fine. The badge count is just broken. We created our account July 12. We are on version 3.2.4 of React Native (the latest is 3.2.5).

jayporta commented 6 years ago

In my experience, after adding App Groups capabilities and adding the group keys, the badge count is reset when the notification is tapped.

Is there a way to reset the count manually? I'd like to reset it when our "new" items are dismissed in the app.

Nightsd01 commented 6 years ago

@jayporta You can set OneSignal_disable_badge_clearing to NO in Info.plist to disable the automatic badge clearing.

Nightsd01 commented 6 years ago

@scottmas The issue you are describing sounds exactly like an issue with the app group not allowing communication between your main app and the extension service, so they get de-synchronized.

Do you happen to have a 2 part bundle ID by chance? (ie. com.test). It's also common to have this issue if your OneSignalNotificationServiceExtension bundle ID isn't exactly the same as your main app's bundle ID (ie. com.test.app and com.test.app.OneSignalNotificationServiceExtension).

In any case, what I would suggest is this: in both Info.plist files (your main app will have one and your extension service will have one as well), set the OneSignal_app_groups_key to be whatever your app group name is. This should fix the problem.

jayporta commented 6 years ago

Thanks, but I don’t want to disable badge clearing, I want to additionally do it programmatically if possible.

On Fri, Aug 10, 2018 at 4:02 PM Brad Hesse notifications@github.com wrote:

@jayporta https://github.com/jayporta You can set OneSignal_disable_badge_clearing to NO in Info.plist to disable the automatic badge clearing.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/geektimecoil/react-native-onesignal/issues/309#issuecomment-412190448, or mute the thread https://github.com/notifications/unsubscribe-auth/AOi1lHe2o7f2BCKpqZLcfU0NNvWJDHoXks5uPebNgaJpZM4PBA6q .

rothanachoun commented 6 years ago

I got the same problem but then i figure out that i forgot to enable App Groups Capabilities in OneSignalNotificationServiceExtension target.

** 1. Under Capabilities enable App Groups for both your main app target as well as the OneSignalNotificationServiceExtension target.

Nightsd01 commented 6 years ago

@jayporta that’s fine, but you would still need to set that plist key to prevent the SDK from automatically clearing the count.

Natively you would call UIApplication.shared.setApplicationIconBadgeNumber to set it to zero yourself.

jayporta commented 6 years ago

Thanks

chiaberry commented 6 years ago

You can set OneSignal_disable_badge_clearing to NO in Info.plist to disable the automatic badge clearing.

@Nightsd01 do we set it as NO or do we set it as <true/> ?

yarodevuci commented 5 years ago

@rothanachoun Thanks man! Helped me.

Ankush-Redapple commented 5 years ago

Please follow https://documentation.onesignal.com/docs/ios-sdk-app-groups-setup in detail.

The name of your app group should be group.{your_bundle_id}.onesignal. So for example, if your application's bundle identifier is com.test.app, your app group name should be group.com.test.app.onesignal.

Assign the group to both target.

  1. Open your Info.plist file and add a new OneSignal_app_groups_key as a String type.
  2. Enter the group name you checked in the last step as it's value.
  3. Make sure to do the same for the Info.plist under the OneSignalNotificationServiceExtension folder.
iphonic commented 2 years ago

If anyone looking for an answer, install react-native-push-notification it has the function of getting and setting application badge count, use it.. Just install the package no need to do any setup, and call PushNotification.setApplicationIconBadgeNumber(number: number). It will work.