简体   繁体   中英

Increase Badge Count From Client side not from Payload Receive count

I am working on application that receives notification and set application badge.
The problem is that when the application is in background state or terminated, the badge count isn't increased.
It remains same.

While when app is in foreground method calls and badge count increased.
I already did that thing from server side,

but I want to know that Is there any method that execute when app is in background or terminated for increasing application badge number?

I already told you I have done this thing as

{
    "aps" : {
        "alert" : "You got your emails.",
        "badge" : 9
    }
}

from server side but what I want is : I dont want to receive that badge count from server payload but I want to increase badge count from my side.

My logic is like that when I receive first notification I saved count in userdeafualts in didReceiveNotification and when I second notification I added count with +1 and when app is in foreground I directly change that badge count as 0 in userdefaults BUT THIS METHOD CANT WORK IN BACKGROUND OR APP TERMINATED

SO I WANT TO KNOW IF THERE IS ANY METHOD THAT EXECUTES IN BACKGROUND OR APP IS TERMINATED SO I CAN INCREASE BADGE COUNT

If anyone knows please help me do it from my side.

Use application(_:didReceiveRemoteNotification:fetchCompletionHandler:) of UIApplicationDelegate . System wakes up your app, if you enabled the remote notifications background mode. For more info check the documentation for this method

To receive a push notification when your app is in the background you need to update the Capabilities of your Target in Xcode and add Background Modes...Remote Notifications. You must then add the key content-available to the payload and set to 1. This will trigger application:didReceiveRemoteNotification:fetchCompletionHandler: . See the documentation here .

When the app is terminated there is nothing you can do.

如果您要签入AppDelegate.m文件,可以使用一种方法来了解该应用程序是否在后台。

- (void)applicationDidEnterBackground:(UIApplication *)application

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM