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 theplayback
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
Having Trouble with Musickit Sample App Provided by Apple
Cloudkit: How to Access Main User's Attributes
How to Show Cluster for Mkpolyline with Geojson Data View in iOS Swift
External Library Usage in Xcode
Why Run Loop Is Needed When Using Dispatchqueue.Main.Async in MAC Command Line Tool in Swift
Syntax to Create Dictionary in Swift
When Creating Thread Safe Reads in Swift, Why Is a Variable Create Outside The Concurrent Queue
Swiftui Sheet Shows Sheet with Wrong Data
Working Out The Start and End of a Day. Swift
Swift Execute Command Line Command in Sandbox Mode
Can't Unwrap Optional.None When Setting Window Background Color
Why Does Editing a Textfield Throw a Nsinvalidargumentexception
Trouble Passing Array Through Prepareforsegue
How to Bend a Rectangle in Sprite Kit
Why Extensions Cannot Add Stored Properties
How to Use Protocols for Stucts to Emulate Classes Inheritance