0

I'm having a problem with my badge incrementation. I'm using the CloudKit push notifications, and when my app receives a push notification, it increments up from the last notification number.

So even when I reset it to zero using:

UIApplication.sharedApplication().applicationIconBadgeNumber = 0

...in the AppDelegate.swift method, it will start from a higher number like 15 - not 1.

I should mention that my app can receive push notifications. When the above code is triggered, the badges go away (as if the badge counter were reset to 0), but this is temporary.

This has been driving me nuts. Can someone out there help me?

John
  • 2,820
  • 3
  • 30
  • 50
user3136022
  • 87
  • 10

1 Answers1

3

Your badge count is sent inside the payload of the push notification.

[aps: {
    alert =     {
        body = "some body text for notification banner";
        title = "title of the banner";
    };
    badge = 1; // the count that will be set to the badge
    sound = default;
    }, userInfo: {
    // some key/value pairs for further processing. // e.g. deep linking.
}]

You should set a breakpoint on public func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) and print the contents of the userInfo dictionary. Check the badge count.

some_id
  • 29,466
  • 62
  • 182
  • 304
  • This is the print report [aps: { alert = "New event has been posted: >"; badge = 24; }, ck: { ce = 2; cid = "iCloud.NV.Project-Oasis"; nid = "e0e8d0ff-ea6f-4b81-abce-90ccf359dbae"; qry = { //stuff }; }] – user3136022 Aug 06 '15 at 10:07
  • Sorry, I don't know why it doesn't let me post the reply in a cleaner way. – user3136022 Aug 06 '15 at 10:09
  • So the badge count is "badge = 24". You need to look at the server or service generating the payload. The counter is not being sent correctly if it is accumulating to 24. – some_id Aug 06 '15 at 12:03
  • What service are you using for your push notifications? What generates them? – some_id Aug 06 '15 at 12:51
  • Could this help? - http://stackoverflow.com/questions/25120070/cloudkit-wont-reset-my-badge-count-to-0 – some_id Aug 06 '15 at 12:53
  • I saw this already and tried it. I got the same error as the guy who commented. There's an internal server error. – user3136022 Aug 06 '15 at 12:55