2

I have a method I would like to execute (non repeating) after a time delay.

I could use performSelector:afterDelay or I could schedule an NSTimer and specify the selector as a parameter to that.

What are the advantages / disadvantages of using one over the other if the end result is the same (which is that my method will be called after the specified time delay). Is it not matter which one I use?

(In case it is relevant, my method will get called both in the foreground and when the app moves to the background during the 10 minute window available via beginBackgroundTaskWithEcpirationHandler).

TIA

Gruntcakes
  • 37,738
  • 44
  • 184
  • 378
  • dupe of http://stackoverflow.com/questions/1490028/iphone-dev-performselectorwithobjectafterdelay-or-nstimer – rishi Jun 05 '12 at 17:01

1 Answers1

3

from the apple reference of NSObject class about performSelector: method

This method sets up a timer to perform the aSelector message on the current thread’s run loop. The timer is configured to run in the default mode (NSDefaultRunLoopMode). When the timer fires, the thread attempts to dequeue the message from the run loop and perform the selector. It succeeds if the run loop is running and in the default mode; otherwise, the timer waits until the run loop is in the default mode.

so if you only want to make single call, I think you can freely use performSelector:afterDelay:

Morion
  • 10,495
  • 1
  • 24
  • 33
  • 5
    Thanks. What is the behavior of performSelector: when the app moves to the suspended state and then back to the active state. Will it fire when the app becomes next active, or will it have been lost? – Gruntcakes Jun 05 '12 at 17:49