Search code examples
iosswifttimer

how do I stop a timer when the app gets into the background or user exits the app


how would I go about to stop a timer when the user exits out of the app, clicks the power button, or gets sent to the background, I realize we can listen to Darwin calls but I do not know how to go about with that.

here's an example from the log out put:

at update 2 I shut the phone off, then at update 6 I turn it on and open the app

1
-LuylG6CvCZNSkLruq9N
updated
2
-LuylG6CvCZNSkLruq9N
2019-11-30 20:17:36.400772-0500 Score[5044:1122736] Can't end BackgroundTask: no background task exists with identifier 13 (0xd), or it may have already been ended. Break in UIApplicationEndBackgroundTaskError() to debug.
updated
3
-LuylG6CvCZNSkLruq9N
updated
4
-LuylG6CvCZNSkLruq9N
updated
5
-LuylG6CvCZNSkLruq9N
updated
6
Fatal error: Index out of range
2019-11-30 20:17:42.889365-0500 Score[5044:1122736] Fatal error: Index out of range
(lldb) 

Solution

  • here's an example on how how'd check:

        if(data.isEmpty == false){
        cell.textLabel?.text = data[indexPath.row]
        }
        return cell