Should I invalidate timer when my application is suspended or in background?

I have scheduler that fetch user profile data every 15 seconds.

class ProfileScheduler: NSObject {

    private var _timer: Timer?

    func start() {
        _timer = Timer.scheduledTimer(timeInterval: 15, target: self, selector: #selector(self.fetchProfile), userInfo: nil, repeats: true)
    }

    func fetchProfile() {
       print("Update........")
       ProfileManager.getProfileData()
    }

}

Should I invalidate Timer each time my application in (Suspended, Background) mode? And restore it when app become (Active).

  • AVPlayer crash when resizing window during fullscreen while hotspotting
  • txt files with invisible line breaks
  • Swift 2: Invalid conversion from throwing function of type to non-throwing function
  • Unique Constraints do not work
  • Objective C Bridging Header for frameworks
  • EXC_BAD_INSTRUCTION only in iPhone 5 simulator
  • Solutions Collect From Internet About “Should I invalidate timer when my application is suspended or in background?”

    Should I invalidate Timer each time my application in (Suspended, Background) mode?

    Yes. See What to do When Your App is Interrupted Temporarily, which explains that you should stop timers and other periodic tasks. Timers need an active run loop to work, so you should stop any timers when your app becomes inactive, and then restart them when it becomes active again.