I thought that the following code would request new data every 5 mins, but there is no update on the simulator.
func getNextRequestedUpdateDateWithHandler(handler: (NSDate?) -> Void) {
print("update")
handler(NSDate(timeIntervalSinceNow: NSTimeInterval(5*60))
}
Do I need some project settings for this?
I have tested it with Xcode 7.1.1 and 7.2 Beta 4
You must handle the scheduled update when it occurs, or ClockKit will stop asking for new timeline entries:
At some point after the date returned by your getNextRequestedUpdateDateWithHandler: method, ClockKit starts a scheduled update of your complication. Scheduled updates do not automatically extend your timeline. Instead, they are an opportunity for you to let ClockKit know whether or not you have data to add to your timeline.
At the start of a scheduled update, ClockKit calls either the requestedUpdateDidBegin or requestedUpdateBudgetExhausted method, depending on the state of your complication’s time budget. You must implement one or both of those methods if you want to add data to your timeline. Your implementation of those methods should extend or reload the timeline of your complication as needed. When you do that, ClockKit requests the new timeline entries from your data source. If you do not extend or reload your timeline, ClockKit does not ask for any new timeline entries.
Your data source is likely missing the optional requestedUpdateDidBegin
method. Here's an example illustrating how to extend your timeline when the update occurs:
// MARK: - Responding to Scheduled Updates
func requestedUpdateDidBegin() {
let server=CLKComplicationServer.sharedInstance()
for complication in server.activeComplications {
server.extendTimelineForComplication(complication)
}
}
Note that the minimum update interval is 10 minutes, so you won't be called every 5 minutes as you expect. Frequent updates also might exhaust your update budget. Apple recommends developers to:
Specify a date as far into the future as you can manage. Do not ask the system to update your complication within minutes. Instead, provide data to last for many hours or for an entire day. If your budget is exhausted, the next scheduled update does not occur until after your budget is replenished.