Updating iOS badge without push notifications

IosNotifications

Ios Problem Overview


I have seen a few todo apps that update their app badges at midnight, always showing the correct number of due tasks. They do this without the use of Push Notifications - so my question is: how do they do this? Do they use local notifications - if so, do these get called when the device is turned off? I'm a little confused and would appreciate some input.

Ios Solutions


Solution 1 - Ios

Try this

[[UIApplication sharedApplication] setApplicationIconBadgeNumber:1];

To do this through local notifications you have to set the value in applicationIconBadgeNumber

UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.applicationIconBadgeNumber = 1;// set here the value of badge

Solution 2 - Ios

And for everyone using new and shiny Swift:

UIApplication.sharedApplication().applicationIconBadgeNumber = someNumber

Swift 3:

UIApplication.shared.applicationIconBadgeNumber = someNumber

Solution 3 - Ios

Since iOS 4.0 you can fire local notifications on all devices that run at least iOS 4.0. Look into the UILocalNotification class, it allows you to set the badge at midnight without having your app running.

Solution 4 - Ios

Set UIApplication's applicationIconBadgeNumber property in your code when application is running:

[UIApplication sharedApplication].applicationIconBadgeNumber = someNumber;

Solution 5 - Ios

For Objective C you have to use:

[[UIApplication sharedApplication] setApplicationIconBadgeNumber : anyNumber ];            

Solution 6 - Ios

Swift 5

UIApplication.shared.applicationIconBadgeNumber = someNumber

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionfabian789View Question on Stackoverflow
Solution 1 - IosraazView Answer on Stackoverflow
Solution 2 - IosJiri TrecakView Answer on Stackoverflow
Solution 3 - IosJustSidView Answer on Stackoverflow
Solution 4 - IosVladimirView Answer on Stackoverflow
Solution 5 - IosVaibhav ShiledarView Answer on Stackoverflow
Solution 6 - IosBenView Answer on Stackoverflow