I try to update the content of my today widget extension every x seconds since I try to realize something like a diashow. Therefor I have stored all required data using shared defaults. Loading data from the storage works perfect but the completionHandler of the extension:
func widgetPerformUpdateWithCompletionHandler(completionHandler: ((NCUpdateResult) -> Void)!) {
//I do load the content here
completionHandler(NCUpdateResult.NewData)
}
Is only called once. How can I implement a function that says that "newData" is available every x seconds?
The one way is NSTimer. It is useful for calling method every x seconds.
var timer : NSTimer?
override func viewDidLoad() {
super.viewDidLoad()
timer = NSTimer.scheduledTimerWithTimeInterval(3, target: self, selector: "animateFrame:", userInfo: nil, repeats: true)
}
func animateFrame(timer: NSTimer) {
// Do something
}
In the case, you can call animateFrame: every 3 seconds.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With