views:

104

answers:

2

Was reading through the iOS4 documentation for multitasking, and couldn't figure it out.

I basically need to update the badge count on my app's icon after midnight each day as long as the app is running in suspended mode (with multitasking).

I know this has to be possible, just can't figure out the best way to do it.

Thanks.

+3  A: 

iOS "multitasking" is very specific. There's an important distinction between states here:

Suspended: Your app resides in memory, but does not receive any execution time. This is really only useful for fast app switching.

Background: In a few particular cases, you can request that the OS to run your app in the background. (Playing audio, location, finishing a long task, voip.)

So, the short answer to your question is, "you can't."

Here are a couple useful links on iOS multitasking, such as it is.

Understand an Application's States and Transitions

Executing Code in the Background

Art Gillespie
Also, "finishing a long task" is really misleading. "long" in that definition is a few seconds, maybe up to about 6 seconds. Not talking hours here.
jer
You have about 5-6 seconds when you enter the background mode before you're suspended.But if your app is, say, uploading images when the user hits the home button, you can request quite a bit of time to complete the upload. [Completing a Long-Running Task in the Background](http://developer.apple.com/iphone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html#//apple_ref/doc/uid/TP40007072-CH5-SW12)
Art Gillespie
You basically can get up to 10 minutes (600 seconds) if you setup a background finish task
Steve Tranby
A: 

You could use a UILocalNotification to set the badge (without an alert) but you can't increment the badge because you're app does not have the opportunity to execute any code when the notification fires.

You can schedule up to 64 notifications in advance, one at midnight for the next 64 days, each one setting a new badge number. It would make a lot more sense to schedule a repeating notification but since your app can't execute code it can't increment the badge number that doesn't work.

progrmr