Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: background notification badge count not increasing #1523

Open
1 task done
bbjay opened this issue Nov 25, 2024 · 4 comments
Open
1 task done

[Bug]: background notification badge count not increasing #1523

bbjay opened this issue Nov 25, 2024 · 4 comments

Comments

@bbjay
Copy link

bbjay commented Nov 25, 2024

What happened?

When sending an iOS background notification with "ios_badgeType": "Increase", it behaves the same as "ios_badgeType": "SetTo"

I use the following API call:

curl --request POST \
     --url https://onesignal.com/api/v1/notifications \
     --header 'Authorization: Basic YOUR_REST_API_KEY' \
     --header 'accept: application/json' \
     --header 'content-type: application/json' \
     --data '
{
  "app_id": "app id",
  "include_player_ids": [
    "Subscribed device id"
  ],
  "content_available": true,
  "ios_badgeType": "Increase",
  "ios_badgeCount": 5
}
'

When sending a normal foreground notification (with content), "ios_badgeType": "Increase" is behaving as expected.

Steps to reproduce?

1. Send a background notification with the above API call and "ios_badgeCount": 5
2. Notice badge count on app icon to show "5"
3. Send background notification again, but with "ios_badgeCount": 1
4. Notice badge count on app icon to show "1"

What did you expect to happen?

Badge count on app icon should show "6"

OneSignal iOS SDK version

3.12.10, 5.2.8

iOS version

17

Specific iOS version

17.4

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

edit: updated affected SDK versions

@filecc
Copy link

filecc commented Nov 26, 2024

Same here, nothing seems to work.

{
  "app_id": "APP-ID",
  "target_channel": "push",
  "headings": {"en": "English Title"},
  "contents": {"en": "English Message"},
  "include_aliases": {
    "external_id": [
      "ID"
    ]
  },
   "ios_badgeType": "SetTo",
   "ios_badgeCount": "5"

}

@bbjay
Copy link
Author

bbjay commented Nov 27, 2024

@filecc your issue seems to be with foreground notifications (as you include a "contents" key in your request). This issue is specifically about background notifications.
I can recommend you to re-check your setup for Notification Service Extension, and App Groups,
and open a new/separate issue if you cannot get it to work.

@bbjay
Copy link
Author

bbjay commented Nov 27, 2024

I did some further digging and found that the latest SDK v5.2.8 has this issue too. When testing with the new SDK, I also used the new API:

curl --request POST \
     --url 'https://api.onesignal.com/notifications' \
     --header 'Authorization: Basic YOUR_REST_API_KEY' \
     --header 'accept: application/json' \
     --header 'content-type: application/json' \
     --data '
{
  "app_id": "YOUR_APP_ID",
  "target_channel": "push",
  "include_subscription_ids": [
    "SUBSCRIPTION_ID_1",
  ],
  "content_available": true,
  "ios_badgeType": "Increase",
  "ios_badgeCount": 1
}
'

wich leads to the same issue.

When checking the contents of the background notification with the OneSignalExample app,

OneSignalExample[6803:2035134] application:didReceiveRemoteNotification:fetchCompletionHandler: {
  aps =     {
      badge = 1;
      "content-available" = 1;
      "mutable-content" = 1;
  };
  custom =     {
      "badge_inc" = 1;
      i = "12494bc4-0916-48a8-ae1d-26881e25183c";
  };
}

i noticed that the aps dict also contains badge: 1, which in my understanding gives iOS the instruction to set the badge count to 1. This may not be the root cause of the issue, but at least it makes it harder to implement an "Increase" functionality in the delegate method on my own, as I have to keep & persist the current badge count too.

I would expect the aps.badge key to be present only when "ios_badgeType": "SetTo" is given.

@nan-li
Copy link
Contributor

nan-li commented Dec 5, 2024

Hi @bbjay thanks for reporting. We will take a look into this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants