1 year ago

#163522

test-img

sergey_s

Something calls a method when the app is in the background

I am using a timer to check certain conditions every minute. Timer code:



func startTimer() {
        timer?.invalidate()
        timer?.tolerance = 0.2
        timer = Timer.init(fire: Day.dateWithNextMinute(), interval: 5, repeats: true) { [weak self] _ in
            self?.checkToPass()
        }
        RunLoop.current.add(timer!, forMode: .default)
    }

Everything works correctly.

But there were problems: for some users, the application began to crash when app is in the background, due to an unhandled value in the checkToPass() method (identified by the logs). I can't figure out how this method can be called when the application is in the background. Is it possible that RunLoop has a side effect and somehow the body of the timer can be called (in the background)? Or maybe it's the timer?

No specific crash time was found. The app was just in the background. 

Thanks for any ideas


swift

timer

background

nsrunloop

0 Answers

Your Answer

Accepted video resources