dgund
dgund

Reputation: 3467

What happens to my NSRunLoop and timer when the app goes into background and returns?

I have an NSRunLoop in my app connected to a timer:

NSTimer *updateTimer = [NSTimer scheduledTimerWithTimeInterval:300 target:self selector:@selector(onUpdateTimer) userInfo:nil repeats:YES];
[[NSRunLoop mainRunLoop] addTimer:updateTimer forMode:NSRunLoopCommonModes];

When the app goes into background, what happens to this runloop? Does it disappear, meaning I should recreate it in applicationDidBecomeActive:?

Upvotes: 7

Views: 1269

Answers (1)

Caleb
Caleb

Reputation: 124997

You should stop your timers when your app is suspended and restart them in -applicationDidBecomeActive:. See "What to Do When an Interruption Occurs" in Responding to Interruptions. You don't have to worry about the run loop, though -- the OS will take care of that part.

Upvotes: 8

Related Questions