The fact that you are using a GCD timer (an alternative to Timer
that can run on background threads) makes me wonder if you are conflating two completely different uses of the word “background”:
One meaning of “background” is related to background queues or threads while an app is running. This is in contrast to the “main” thread/queue.
And, yes, GCD timers are different than Timer
instances insofar as they can run on background queues (assuming the app, itself, is actually running).
The other meaning of “background” is related to the state of an application. You can either be running in the foreground, running in the background, or be suspended/terminated.
While an app is running (either in the foreground or the background), timers (either GCD timers or standard Timer
) can operate. But if an app is suspended or terminated, all execution will stop, including timers.
The problem is that you’re trying to run a timer while the app, itself, has been suspended. That will not work.
Your app will not run in the background unless you either:
request a little time to finish some finite length task (which is only runs for 30 seconds in recent iOS versions); or
your app has some background mode enabled for some approved purpose (e.g. navigation, music, VOIP, etc.).
But apps can’t continue to run in the background (timers or anything else), except for those special, narrow situations (e.g. VOIP, music, navigation apps, etc.). For more information about background execution see:
And, even in iOS 13 and later, where more generalized background tasks are permitted, they’re intended for finite length tasks that will be initiated at the sole discretion of the OS (determined by power, wifi, frequency with which the user fires up the app, etc.). For more information, see WWDC 2019 Advances in App Background Execution.