I’m using CKSubscription to send push notifications, I send them well and the device receives everything correctly, but my badge count is always +1 to what it was before? How can I set it to 0 after the app was run?
I have added this code to func application didFinishLaunchingWithOptions
UIApplication.shared.applicationIconBadgeNumber = 0
But when you run the app, the badge disappears, receiving the next push notification the number rises again.
It sounds like you're just not zeroing it out at the right place?
didFinishLaunchingWithOptionsis not called when your app resumes from background, only when it is actually launched. The most common use of the badge I can think of is when you are receiving notifications and you want to zero them when the user has seen the notifications. So that's where you have to set yourapplicationIconBadgeNumber = 0If for instance your app is just a single view with a list of messages and just seeing that list is enough to tell you the user has read the message you could use
applicationWillEnterForegroundinstead. That is called every time you come back from being in the background.You still also have to zero it out when a notification comes in while the app is in the foreground though.