开发者

How do I get a codeblock to run on the iPhone once every 24 hours at midnight if my app is suspended (multitasking)

开发者 https://www.devze.com 2023-01-07 07:28 出处:网络
Was reading through the iOS4 documentation for multitasking, and couldn\'t figure it out. I basic开发者_如何学Goally need to update the badge count on my app\'s icon after midnight each day as long a

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

I basic开发者_如何学Goally 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.


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消