So, after sooo so much testing and online research, I have to give up and ask for help. WatchOS 2 complications.
So I am trying to create a basic complication that shows the time at the time of update.
I am aware that update in background are budgeted so I am attempting to update the time every 10 mins. Hopefully as collecting an NSDate is simple, that won't cause me to go 'over budget' what ever that means.
I am for now ignoring time travel and providing a timeline. Instead I am simply filling out the large module template with the current time in:
func getCurrentTimelineEntryForComplication(complication: CLKComplication, withHandler handler: (CLKComplicationTimelineEntry?) -> Void) {
I then have this:
func getNextRequestedUpdateDateWithHandler(handler: (NSDate?) -> Void){
handler(NSDate(timeIntervalSinceNow: 60*10));
}
And this:
func requestedUpdateDidBegin(){
NSLog("requestedUpdateDidBegin")
let complicationServer = CLKComplicationServer.sharedInstance()
for complication in complicationServer.activeComplications {
complicationServer.reloadTimelineForComplication(complication)
}
}
The update never ever occurs though. Only by launching the extension and running the same code as 4 lines above, can i get the complication to update. From looking at the logs, all that happens after a forced update is that the method getNextRequestedUpdateDateWithHandler gets called but nothing else.
Any suggestions or anything that I am obviously missing? Thanks very much for reading.
I would think you need to implement:
func getCurrentTimelineEntryForComplication(complication: CLKComplication, withHandler handler: ((CLKComplicationTimelineEntry?) -> Void))
The method you have implemented getTimelineEntriesForComplication(complication: CLKComplication, beforeDate...
is only called when the complication server is gathering timeline entries for forward time travel.
Given the scenario you describe, I would strongly recommend supporting forward time travel by implementing:
func getSupportedTimeTravelDirectionsForComplication(complication: CLKComplication, withHandler handler: (CLKComplicationTimeTravelDirections) -> Void) {
handler([.Forward])
}
And
func getTimelineEndDateForComplication(complication: CLKComplication, withHandler handler: (NSDate?) -> Void) {
let date: NSDate = // Your date
handler(date)
}