I need to keep a thread running even when the user is inside another application. I tried the following thread that works only if I keep the application visible, once I press the home button, the thread is paused.
func prepareSync() {
DispatchQueue.global(qos .background).async {
self.sync()
sleep(5)
self.prepareSync()
}
}