Should I Invalidate Timer When My Application Is Suspended or in Background

Is a Timer disabled automatically when app resigns active on the iphone?

Your app is suspended when it enters background mode (Application States and Transitions).

Your timer won't fire when the app is in background and the time spent in background isn't taken into account for the timer delay.

Timer stops despite background capability is enabled

The question has some false premises:

  • applicationDidEnterBackground does not mean your app will be suspended. It usually does, but if you have the audio background mode capability and the playback audio category, and you are playing sound when you go into the background, you are not suspended; instead, you run in the background.

  • A timer that is started before you go into the background does work in the background under those circumstances.

So if you're hearing sound in the background from your app but your timer is not firing, that must be due to something else you're doing. Perhaps you've configured things so that the timer is invalidated when you go into the background?

Is NSTimer expected to fire when app is backgrounded?

NSTimer is going to fire whenever the main runloop is running. Apple makes no promises that I know of to unschedule timers or to prevent the main runloop from running. It's your responsibility to unschedule your timers and release resources when you move to the background. Apple isn't going to do it for you. They may, however, kill you for running when you are not supposed to or using too many seconds.

There are many holes in the system that will allow an app to run when it isn't authorized to. It would be very expensive for the OS to prevent this. But you cannot rely on it.

NSTimer not stopping after the app goes into background

Because you are using background modes with location and audio your app is still alive in background.and so your timers are running.

If you remove background modes with location and audio that you are using and then try the timers wont work.

Its Normal behaviour. Correct me if i'm wrong.



Related Topics



Leave a reply



Submit