1

This is the code I have and I it puts the date in a application badge. I was wondering how to reload this number everyday without entering the app to reload it. Thanks in advance!

NSDate *today = [NSDate date];
NSCalendar *cal = [NSCalendar currentCalendar];
NSDateComponents *comp = [cal components:NSDayCalendarUnit fromDate:today];
NSInteger day = [comp day];
[UIApplication sharedApplication].applicationIconBadgeNumber = day;
paulmelnikow
  • 16,470
  • 7
  • 60
  • 112
Luke
  • 55
  • 5

2 Answers2

1

A relatively easy way would be to put the code that sets the badge in the background. You can use [UIApplication beginBackgroundTaskWithExpirationHandler] or a related call for this purpose. The only problem is that there's a 10 minute limit for such execution. Having said that, there are tricks that can be used to circumvent that limit. Here is an excellent thread that discusses this topic: Run app for more than 10 minutes in background

Community
  • 1
  • 1
er0
  • 1,621
  • 1
  • 15
  • 27
0

I have following code :

NSDate *fireTime = [[NSDate date] addTimeInterval:3600*24];
notification.fireDate = fireTime;
notification.alertBody = @"Your Message!";
notification.applicationIconBadgeNumber = 1;
[[UIApplication sharedApplication] scheduleLocalNotification:notification];

If you are testing on simulator then probably that is the reason why you are not getting the output. Test it on device and see whether is it working .

V-Xtreme
  • 7,009
  • 8
  • 37
  • 79