Timer operation in background state

I set the project's background mode as above.

I'm using the timer with the mic on. The timer currently works in the background, but the timer is paused during a phone call. Do you want to run a timer while on a call, but there is no way?

I am using timer as below.

playTimer = Timer.scheduledTimer(withTimeInterval: 0.03, repeats: true, block: { [weak self] _ in
      self?.sendBuffer()
    })

iOS typically suspends apps that are in the background. If your app is suspended, any timers you schedule won’t fire.

I'm using the timer with the mic on.

It sounds like your app is running an audio session and that’s prevents it from being suspended.

the timer is paused during a phone call

What sort of phone call? A phone call being run by your app? Or a phone call being run by some other app?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

An audio session is running. And the phone running in the app (default phone app).

If the app is running an audio session, and thus not suspended, the timer should continue to fire as it would if the app were in the foreground. My suggestion is that you add a log point to your timer to confirm that the timer itself has actually stopped. So, change your code to look something like this:

import os.log

let log = Logger(subsystem: …, category: …)

class … {

    func …() {
        …
        playTimer = Timer.scheduledTimer(withTimeInterval: 0.03, repeats: true, block: { [weak self] _ in
            log.debug("timer fired")
            … your code here …
        })
        …
    }
}

Then monitor your chosen subsystem and category using Console.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

log check result Normal state: log output regardless of background state Call Status: No log output. After the call ends: The log is printed again.

Is it normal operation?

Timer operation in background state
 
 
Q