'Swift Timer How to invoke timer calls when app goes down using iCloud
I have timer based code running perfectly when the app is running. Both the timer based functions get called and I am able to update iCloud CKRecord. But if accidentally app goes done or user kills it, the timer code cannot be invoked. Is there a iCloud mechanism, or some technique anyone can suggest to remember and invoke timer calls and code to execute?
let currentDateTime = Date()
let calendar = Calendar.current
var tempDateTime1 = calendar.date(byAdding: .minute, value: 1, to: currentDateTime)
var tempDateTime2 = calendar.date(byAdding: .minute, value: 2, to: currentDateTime)
DispatchQueue.main.async {
let userInfo:Dictionary<String, String> = ["tag": orderCkRecordName]
let startTimer = Timer(fireAt: tempDateTime1!, interval: 0.0, target: self, selector: #selector(self.beginOrderUpdate(sender:)), userInfo: userInfo as Dictionary, repeats: false)
let endTimer = Timer(fireAt: tempDateTime2!, interval: 0.0, target: self, selector: #selector(self.endOrderUpdate(sender:)), userInfo: userInfo as Dictionary, repeats: false)
RunLoop.current.add(startTimer, forMode: RunLoopMode.commonModes)
RunLoop.current.add(endTimer, forMode: RunLoopMode.commonModes)
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
