5

I have an app that I want to update the badge icon weekly. I see that at least pre iOS7, UILocalNotification could only set the badge icon to a specific number like

someLocalNotification.applicationIconBadgeNumber = 42;

But I want my app to load in the background lets say every sunday, do a calculation based to get the difference between the current date and some start date, and update the badge number accordingly.

UILocalNotification can't do this apparently. It looks like push notifications can, but I don't have a server component for this app, so using that as a workaround wouldn't work, and I'm not sure Apple would like it anyway.

I know there is some background app refresh updates in iOS7, but I'm not sure if they would work in this situation.

TLDR: How do I update a badge icon in iOS7 that requires a bit of calculation to get the correct number, on a weekly basis (or any arbitrarily long time basis)? And I want to do this background updating without a server component.

NickH
  • 683
  • 1
  • 5
  • 24
  • Is your question based on how to calculate your desired number or a question on how to set the badge number without a server component? – Pavan Feb 13 '14 at 01:22
  • @Pavan How to set the Badge number without a server component. – NickH Feb 13 '14 at 01:35
  • cont. So you need to schedule new ones if you want new numbers for your badge. – Pavan Feb 13 '14 at 01:40
  • @Pavan Thank you for this link. I did not find it in my searches for the answer. While it feels kind of silly to schedule several single notifications in advance when a repeat would work fine, this works with my app. I do wonder if there is some performance hit for doing this, but I need less than the 64 max notifications, so it will work for me. Thanks. – NickH Feb 15 '14 at 06:43

1 Answers1

0

You simply schedule a silent local notification, with a nil message and then update the badge number. Also set the repeat count to nil otherwise the badge wont get updated if you call this local notification multiple times

This person posted a similar question, have a look

Community
  • 1
  • 1
Pavan
  • 17,840
  • 8
  • 59
  • 100