我已在主线程上安排了NSTimer。
func startTimer(){
MYClass.runUIBlock { () -> Void in
self.invalidateRecordTimer()
self.updateTimerForInactiveRecord(self.fiveMinutesInSeconds)
}
}
private func updateTimerForInactiveRecord(timeToRecord:Double){
recordTimer = NSTimer(timeInterval: timeToRecord, target: self, selector:"collectData", userInfo: nil, repeats: true)
NSRunLoop.currentRunLoop().addTimer(recordTimer!, forMode: NSRunLoopCommonModes)
}
即使我在后台,计时器也会继续运行。想要问一下,在后台计时器结束之前保持定时器开启而不会使其无效是否安全?或者我需要检查可用的后台时间并在后台计时器结束之前使计时器无效? 目前,计时器在后台无限期地继续运行。
答案 0 :(得分:0)
NSTimer在后台运行时最多只能运行10分钟。 Apple有目的地做到这一点,以避免电池排水。如果你不应该在后台做重要的活动,那么作为一个好公民,建议在后台进行时停止计时器。