How can I continue running my timer in the background?

Hello, I am having an issue in my app. I cannot continue running the timer when I go to the background. I got the message Can't end BackgroundTask: no background task exists with identifier 1 (0x1), or it may have already been ended. Break in UIApplicationEndBackgroundTaskError() to debug. I already signed the capabilities for Background but I cannot figure out how to solve this.


Here is my code:


    

    var timer = Timer()
    var teas = Teas()
    var isTimerRunning = false
    var alarmSound = AVAudioPlayer()
    var playing = false
    var initialValueOfTime = 0
   
    var teaMinutesLabel = ""
   
    private let notificationPublisher = NotificationPublisher()
   
    override func viewDidLoad() {
        super.viewDidLoad()
       
        overrideUserInterfaceStyle = .light
       
        initialValueOfTime = teas.time
        runTimer()
        timeFormatted(
    }
 
   
    //RunTimer()
    @objc func runTimer() {
       
        if isTimerRunning {
            teas.time -= 1
           
            if teas.time <= 0 {
                timer.invalidate()
                let url = Bundle.main.url(forResource: "AlarmSound1", withExtension: "wav")
                alarmSound = try! AVAudioPlayer(contentsOf: url!)
                alarmSound.play()

               
                if alarmSound.isPlaying {
                    startButton.setTitle("Done", for: .normal)
                    playing = true
                }
            }
        }
        else {
            teas.time = initialValueOfTime
        }
    }