views:

63

answers:

1

How can you have the simplest tast happen after 5-10-60 minutes on iOS? Essentially, have an NSTimer fire after a predefined interval.

I do "begin task", sleep( for some time ); and then "end task". However my app usually gets killed if I sleep for more than 5 minutes. I've seen posts around that mention that apps can stay alive in the background for a few hours, how exactly can that be achieved?

+1  A: 

When your app goes to the background, the system will try to recollect as many as resources as you can give it to him like Images, nibs, etc. You have a notification for this. (– applicationDidEnterBackground:, etc) After that, it will "sort" all the background living apps according the resources usage order. The app that uses more resources comes first. Then when a new app comes to the foreground if the systems thinks it needs more resources than it currently has it will start killing background apps. using the above sorted list.

This means that the less resources you use in the background, the longer your app will live. BUT, there is no guarantee it will live long. (Everything depends on user usage). There is also no notification when it gets killed!, so you cannot assume your app will live for 60 min.

You probably want to read this Apple doc on how to do something in the background (with some time restrictions, off-course) and probably also UIApplicationDelegate class reference.

Hope it helps ;)

nacho4d
Thanks for this, I've read these docs but can't find specific instructions on how to things. I think I might try to use "setKeepAliveTimeout:handler:" and register my app as a VOIP app and see if Apple rejects it... That seems to be the safest option. Before that I will try to release all my app's resources, nibs and images as you mentioned, even though it was not using much anyway.
Dimitris