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 5 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

jkasten2 commented 5 years ago

@SamJWeissman Can you double check that you have followed the setup under "iOS - Add App Groups" AND "iOS Service Extensions" https://documentation.onesignal.com/docs/cordova-sdk-setup#section-ios-add-app-groups-optional-but-recommended-

Both are needed to support the badge increase option

SamJWeissman commented 5 years ago

@jkasten2

I definitely followed all of the steps from both of those sections. The badge increase is working, and being grouped properly on our apps icon.

It just doesn't reset to 0 when the app is opened... it is VISUALLY cleared ( the badge no longer shows ), but when I get a new notification, it resumes from where it left off.

Nightsd01 commented 5 years ago

@SamJWeissman this is definitely an app group issue. Can you send screenshots of the App Group capability for both your app target and Extension Service target? Also, what is your app’s bundle ID?

SamJWeissman commented 5 years ago

Hi @Nightsd01,

The apps bundle ID is com.waiport.mobile

Here are the screenshots you've requested.

App Target

screen shot 2018-11-15 at 11 29 45 am

Service Extension Target

screen shot 2018-11-15 at 11 30 09 am

Greatly appreciate both of you trying to help out here.

Nightsd01 commented 5 years ago

@SamJWeissman Can you post the bundle ID for your Notification Service Extension target?

Nightsd01 commented 5 years ago

@SamJWeissman Let's also try something else. In your Info.plist for both the app and extension service, add the following key+string pair:

OneSignal_app_groups_key = group.com.waiport.mobile.onesignal

Then go ahead and test and let me know if the issue still occurs?

SamJWeissman commented 5 years ago

@Nightsd01 Sorry was pretty swamped yesterday!

Attached are the screenshots with bundle identifiers.. Going to try updating the Info.plist and will let you know if any improvement.

screen shot 2018-11-16 at 7 40 03 am screen shot 2018-11-16 at 7 40 19 am
SamJWeissman commented 5 years ago

@Nightsd01

Updated the app Info.plist as well as the OneSignalNotificationServiceExtension Info.plist with those key / value pairs. Unfortunately, the badge count is still not being reset to 0.

SamJWeissman commented 5 years ago

@Nightsd01 @jkasten2

This is still an issue for us unfortunately. I tried manually resetting the count using POSTMAN

ie: Made a PUT request to https://onesignal.com/api/v1/players/<my-player-id> with Content-Type: application/json, Authorization: Bearer-<my-api-key>, and body as

{ app_id: <my-app-id>, badge_count: 0 }

While hitting this endpoint is returning {"success": true"}, the badge count on iOS remains unchanged.

Was hoping if that endpoint had worked, I'd be able to manually reset the badge counts whenever a user viewed their in app notifications. But this appears to be a dead end as well.

Nightsd01 commented 5 years ago

@SamJWeissman Sorry for the delay in getting back to you. Calling that endpoint won't do anything since badge count logic is now handled on the client.

Just to be sure, you are testing this on a real iOS device running iOS 10 or higher, right?

Can you try sending a rich push notification (with an image or something) and tell me if that works?

pablokintopp commented 5 years ago

Hi @Nightsd01, we are facing the exact same problem as @SamJWeissman and I can confirm to you that sending rich push notification is working for us.

Trying to solve the problem, we did everything you suggest in this thread. In addition, we also tried adding the flag OneSignal_disable_badge_clearing to "YES" in our info.plist file (on the main target). Thus, we expected to handle the badge logic on the App side by using another cordova plugin.

However, despite the fact that it seems to be working when we test locally, after publishing to Apple it continues with the same problem.

Nightsd01 commented 5 years ago

@pablokintopp

  1. Did you create your OneSignal app in or after June 2018? If so, it will be using client side badge logic.

  2. If so, this means you are definitely facing an issue where the Extensions Service cannot communicate with your main app using an App Group.

Note that this logic only works in iOS 10 and later.

Can you please share a screenshot for where you typed the names of your app group? Both in the main app target and extension target.

pablokintopp commented 5 years ago

@Nightsd01

Yes, I can confirm that the OneSignal app was created after June 2018. We also are aware that IOS 10+ is required to work.

Bellow are the screenshots you asked:

ios_print_1 ios_print_2
clemishow commented 5 years ago

Facing the same problem. Same for Android on a real device. Same for IOS on a real device.

I'm using https://github.com/katzer/cordova-plugin-badge 0.8.8

@pablokintopp Have you found a solution ?

pablokintopp commented 5 years ago

@clemishow I couldn't find a solution yet.

I'm using the same badge plugin as you (version 0.8.7).

clemishow commented 5 years ago

Really need this feature !

Nightsd01 commented 5 years ago

@clemishow I would suggest removing the badge plugin to see if that fixes the auto increment issue.

Can you also try running our OneSignal Cordova Example project and let me know if this same issue occurs there (after you set it up with your same App ID, bundle ID, same app group on both the app and extension targets)

clemishow commented 5 years ago

@Nightsd01 Ok but how to decrement the badges and clean them with OneSignal?

chagaspac commented 5 years ago

Same problem here, using here: cordova-plugin-badge - 0.8.7 onesignal-cordova-plugin - 2.4.1

Followed all those steps in https://documentation.onesignal.com/docs/ios-sdk-setup#section-1-add-notification-service-extension and in https://documentation.onesignal.com/docs/ios-sdk-app-groups-setup

Nightsd01 commented 5 years ago

@chagaspac are you using a badge plugin? That can interfere with our badge logic and we haven’t had time to investigate yet so in the mean time I’d suggest removing any badge plugin.

If not, please post screenshots of the app group capability for both the main app target and the extension service target.

chagaspac commented 5 years ago

It's just installed, but I'm not using anymore. I will uninstall it and try again.

Follow the screenshots: image image

Edit: I'm testing in real devices, through TestFlight and handling notifications normally. In android this problem (not resetting badge) don't happen.

chagaspac commented 5 years ago

I uninstalled the badge plugin from npm and Cordova plugin, redeployed at TestFlight, and didn't worked.

Nightsd01 commented 5 years ago

@chagaspac please add OneSignal_app_groups_key = your app group name to the Info.plist files for both the app and the extension service (they will have their own separate Info.plist files)

Goregut commented 5 years ago

Having the same issue here. Badges increment fine. They "clear" on resume, but then the next notification just increases the previous count. So after reading around for solutions, I too started using the badge plugin in hopes of just being able to clear. All the badge plugin calls I have tried seem to "work" as well.

I followed the set up guide for iOS and am using the One Signal Notification Service Extension, and I have added the OneSignal_disable_badge_clearing.

example. App in background and notification raised badge count to 12. I was testing, and set the badge plugin to set the badge count to 20 on resume. Put app back into background and the badge was 20. When I sent the next notification it changed to 13. So somewhere it's still keeping the count.

using: cordova-plugin-badge - 0.8.8 onesignal-cordova-plugin - 2.4.6

Nightsd01 commented 5 years ago

@Goregut please read the comments above and troubleshooting steps. Adding a separate badge plugin will literally only make this problem worse.

You likely have a mismatch issue with your app group name. If not, try adding the app group name to your info.plist as I’ve detailed above.

Goregut commented 5 years ago

@Nightsd01 Sorry, thought I'd already tried that. To confirm my badges seem to be working and staying cleared after removing all the custom stuff I added and then put the OneSignal_app_groups_key = groups.mygroupsman in the info files.

Thanks for the help.

clemishow commented 5 years ago

@Goregut Can you decrement the badges one by one? Clear the badges work?

Nightsd01 commented 5 years ago

@goregut I’m a bit confused then, what exactly is the issue you are having..?

Goregut commented 5 years ago

@Nightsd01 Originally I was having issues with the badges staying cleared. They would clear out on resume, but then the next notification would add to the number it was before it was cleared. Now after adding the groups in the info.plist files things seem to be working how I need them.

@clemishow I'm not sure. I haven't tried decrease them. I don't have a use case for needing to do it yet.

chagaspac commented 5 years ago

@Nightsd01 I've added this key with the same group name and I'm waiting for review to test with others features. (I don't have right now a physical device to test it with TestFlight).

chagaspac commented 5 years ago

@Nightsd01 The problem wasn't resolved with the fix

Nightsd01 commented 5 years ago

@chagaspac are you sure that you added OneSignal_disable_badge_clearing to both Info.plist files (for the app itself and the Extension service)?

It’s going to take a LONG time to debug this if you are actually testing each step with a full App Store release..

leszekkrol commented 5 years ago

Same issue on Unity3D plugin

rgomezp commented 5 years ago

@chagaspac closing due to no response.

Please @ me and I will reopen if anyone is still having this issue.

@leszekkrol please file an issue in the Unity SDK repo

nikolmedo commented 5 years ago

@rgomezp I still with the problem

rgomezp commented 5 years ago

Just to summarize, the fix that has worked for folks is adding OneSignal_app_groups_key & value in the info files. They also removed any additional badge plugins. Can you confirm you have tried these?

rgomezp commented 5 years ago

Closing due to no response

chenkuanhuaian commented 5 years ago

Hi, I'm facing exact the same problem, badge number is not reset at OneSignal. I have added OneSignal_disable_badge_clearing and OneSignal_app_groups_key to my info.plists as above had suggested, but still, badge number is not reset.

I wonder what might went wrong...

Also, I don't know if that matters but do I have to name my appGroup following this naming rule : group.{your_bundle_id}.onesignal ? because I had named my appGroup following other naming rule.

rgomezp commented 5 years ago

We're aware of the issue and are looking into it. As long as the name is the same in both targets, I think you should be fine. However, it doesn't hurt to follow that naming convention as I'm not the person who wrote the SDK

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.
maxnaza44 commented 5 years ago

I have the same issue. Everything works fine when installed by Xcode while developing but the issue happens when app's installed from Testflight.

However I tried to solve the issue as above suggestions but didn't help.

Ankush-Redapple commented 5 years ago

I have the same issue. Everything works fine when installed by Xcode while developing but the issue happens when app's installed from Testflight.

However I tried to solve the issue as above suggestions but didn't help.

Please check app groups are same for both target - Application and extension. The app group id should be like: group.{your_bundle_id}.onesignal. You must follow the naming convention. Also you have to add OneSignal_app_groups_key in info.plist of both target and put the group name.

These are only the steps, I have solved the issue.

maxnaza44 commented 5 years ago

@Ankush-Redapple Could you check my config to find out what's wrong? Thanks for your help.

https://imgur.com/a/oGlNjxy

fmorau commented 5 years ago

@SamJWeissman this is definitely an app group issue. Can you send screenshots of the App Group capability for both your app target and Extension Service target? Also, what is your app’s bundle ID?

Didn't know that I have to set it also to NotificationService --> Then I had this issue. Solved for me! Thank you!

rricamar commented 5 years ago

Hi,

This is happening also to me randomly, sometimes works, sometimes not... I'm following the name convention and the official guide, so theoretically the .plist step is not required.

Could be this any issue with the SDK? 😰

rricamar commented 5 years ago

I have the same issue. Everything works fine when installed by Xcode while developing but the issue happens when app's installed from Testflight.

However I tried to solve the issue as above suggestions but didn't help.

I think that is something random, same here: from TestFlight isn't working ❌

manudefrutosvila commented 5 years ago

I have the same issue. Everything works fine when installed by Xcode while developing but the issue happens when app's installed from Testflight. However I tried to solve the issue as above suggestions but didn't help.

I think that is something random, same here: from TestFlight isn't working ❌

Same here, I don't why sometimes it works or not, the guide is pretty clear I think, and I'm doing the steps as always... From Xcode works, but from Testflight it doesn't

rricamar commented 5 years ago

Hi again ✋ ,

Reviewing the Release Notes, I saw that in version v2.4.2 this was fixed:

Fixes an issue that would occasionally cause the SDK to be unable to automatically retrieve the App Group name, which was used to enable communication between the Service Extension and the main app. The main side effect of this issue would have been inconsistent badge logic, where the SDK would not maintain a logically consistent badge count.

Which is exactly what happens to me, could be maybe some regression? I have v2.4.6 right now ...

pppd commented 5 years ago

we are seeing the same issue, works fine when building directly to a device on xcode, once we push to test flight it doesn't clear. we are on v2.4.7 and both .plist do include OneSignal_app_groups_key tag.

maxnaza44 commented 5 years ago

Hey guys, I have already solved this issue. mention to https://github.com/j3k0/cordova-plugin-openwith/issues/48

This is an issue with your entitlements files. Inside your platform folder you can find two files for the Entitlements, one for debug and one for production builds(release). For some reason the plist file for your production builds ( which I assume is necessary for uploading your app to TestFlight) is not updated with the Capapilities you select in XCode. Have a look at the content of the Entitlements-Release.plist file and change it so it has to be the same content as your Entitlements-debug.plist file.

You can find entitlements file location from xCode >> Your Targets >> Build Settings >> then search Entitlements.

For example.

my original Entitlements-Release.plist contains

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>aps-environment</key>
    <string>production</string>
  </dict>
</plist>

So I have to change it to the same as Entitlements-debug.plist......

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>aps-environment</key>
    <string>production</string>
    <key>com.apple.security.application-groups</key>
    <array>
      <string>group.{your_bundle_id}.onesignal</string> <!--Fill your bundle id-->
    </array>
  </dict>
</plist>

will solved this issue.