It is clear how to set the badge number:
[[UIApplication sharedApplication].applicationIconBadgeNumber = whatever
The problem is when to increment it properly. I want it to equal the number of UILocalNotifications that have fired since the app went to sleep. The notifications themselves have a badge value, but that requires you to know in advance the value. Also, a notification can be recurring, so its count/badge value is not clearly defined. (At creation time. Do I have to keep resetting the badge numbers of notifications every time the app wakes?)
If the OS would notify the app (in the background) as well as the user, the app could easily update a static count and set the badge number.
It seems that in iOS 8 there is a registerUserNotificationSettings call, which might enable the OS to do the counting automatically. I don't know. But in any case, how is this done in previous OSes?