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,895
  • 8
  • 63
  • 114
Luke
  • 55
  • 5
  • You could you push notifications... –  Dec 28 '12 at 01:47
  • Yes - push notifications - here's a relevant post: http://stackoverflow.com/questions/11153631/increment-the-push-notification-badge-iphone – bryanmac Dec 28 '12 at 01:48

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,746
  • 2
  • 16
  • 31
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,230
  • 9
  • 39
  • 79