简体   繁体   中英

Push notification badge reset count

I'm using PushBot as my push notification service, my issue is how do I reset the badge count. I've search and read to use this line of code:

[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];

The only way the badge count gets reset is if I quit the app from running on the mulit-task bar and launch the app again, any help is greatly appreciated. Thanks,

Just make a button on your UI and on his action put the code line:

[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];

It will reset it.

Take a look Here for some other implementations.

To clear the badge count whenever the application becomes active, simply include your line of code:

[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];

In the AppDelegate.m file's applicationDidBecomeActive delegate method.

applicationDidFinishLaunchingWithOptions is only called on the initial launch, and does not get called again when the application goes to the background and back to the foreground.

For Swift 3.0

//AppleDelgate.swift
 func applicationDidBecomeActive(_ application: UIApplication) {
        //....
        application.applicationIconBadgeNumber = 0
       //....
}

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