2

I was under the impression it wasn't possible for a background task to execute (apart from a) if it requests from the OS a little extra time to finish things after moving into the background or b) if it uses one of the 3 UIBackgroundModes).

However this thread is talking about creating a background timer

iOS4 Create Background Timer

Yet in that thread there are no mentions made of the general limitations regarding background apps, thus implying that it is actually possible to achieve background exeuction via timers.

Could somebody please clarify this.

If you have an application that calls performSelector : withObject: afterDelay with a long delay time (several hours or several days) and then the application moves to the background and does not have a UIBackgroundMode, what happens when that time passes?

Community
  • 1
  • 1
Gruntcakes
  • 37,738
  • 44
  • 184
  • 378

2 Answers2

0

Why not test?

I guess your application (and run loop) will be suspended and then continued as usual when in foreground again, firing your timer. If you read the documentation for NSTimer you may get a hint about how it works.

http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSTimer_Class/Reference/NSTimer.html

If a timer’s firing time occurs during a long callout or while the run loop is in a mode that is not monitoring the timer, the timer does not fire until the next time the run loop checks the timer. Therefore, the actual time at which the timer fires potentially can be a significant period of time after the scheduled firing time.

In this context they talk about a long callout but a suspend/resume will probably have a similar effect.

Mattias Wadman
  • 11,172
  • 2
  • 42
  • 57
0

The timer is for when the app is in the foreground. It's a background timer in the sense that it executes in the "background" of the main thread.

Simon
  • 1,746
  • 1
  • 13
  • 21
  • In that thread the op states as a requirement: "How can I ensure that the thread remains in the background also." Therefore I assumed his question and thus the replies are within the context of that being a requirement. If he has a requirement for his thread to remain in the background then does this mean the supplied answers therefore irrelevant? – Gruntcakes Dec 05 '11 at 22:32