user3136022
user3136022

Reputation: 97

Whenever my app receives a push notification it increments up from the last badge number (not 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?

Upvotes: 0

Views: 868

Answers (1)

some_id
some_id

Reputation: 29896

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.

Upvotes: 3

Related Questions