我正在尝试在 Watch 应用程序复杂功能中支持 TimeTravel。考虑这段代码。
在我杀死应用程序之前,我无法理解为什么这些委托方法会被重复调用。
我想知道我做错了什么,因为操作系统负责调用这些方法。这是某种 WatchOS 错误吗?
func getTimelineEntries(for complication: CLKComplication, after date: Date, limit: Int, withHandler handler: @escaping ([ CLKComplicationTimelineEntry]?) -> Void) {
// Call the handler with the timeline entries after to the given date
let interval = stride(from:0.0, through:60, by: 10.0)
var entries: [CLKComplicationTimelineEntry]? = nil
switch complication.family {
case .circularSmall:
entries = interval.flatMap({ minutes in
entryForCircularSmall(date: date.addingTimeInterval(60.0 * minutes) )
})
handler(entries)
case .utilitarianLarge:
entries = interval.flatMap({ minutes in
entryForUtilitarianLarge( date: date.addingTimeInterval(60.0 * minutes) )
})
handler(entries)
default:
handler(nil)
}
print("future timelineEntries limit: \(limit), date: \(date), entries: \(entries?.count)")
}
func getTimelineEndDate(for complication: CLKComplication, withHandler handler: @escaping (Date?) -> Void) {
let date = Date().addingTimeInterval(60.0 * Double(240))
print("timeline end: \(date)")
handler(date)
}
控制台日志的一小段摘录:
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:32:59 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:09 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:09 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:09 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:09 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:09 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:09 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:09 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:09 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:09 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:09 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:09 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:09 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:09 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:09 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:09 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:09 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:09 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:09 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:09 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:09 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:09 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:09 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:09 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:09 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:09 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:09 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:09 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:09 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:09 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:09 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:09 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:09 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:09 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:09 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:09 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:09 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:09 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:09 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:09 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:09 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:09 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:09 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:09 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:09 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:09 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:09 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:09 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:09 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:09 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:09 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:09 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:09 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:09 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:09 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:09 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:09 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:09 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:09 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:09 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:09 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:09 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:09 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:09 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:09 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:10 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:10 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:10 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:10 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:10 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:10 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:10 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:10 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:10 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:10 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:10 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:10 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:10 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:10 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:10 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:10 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:10 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:10 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:10 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:10 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:10 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:10 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:10 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:10 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:10 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:10 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:10 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:10 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:10 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:10 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:10 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:10 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:10 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:10 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:10 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:10 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:10 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:10 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:10 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:10 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:10 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:10 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:10 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:10 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:10 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:10 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:10 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:10 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:10 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:10 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:10 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:10 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:10 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:10 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:10 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:10 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:10 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:10 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:10 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:10 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:10 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:10 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:10 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:10 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:10 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:10 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:10 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:10 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:10 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:10 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:10 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:10 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:10 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:10 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:10 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:10 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:10 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:10 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:10 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:10 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:10 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:10 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:10 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:10 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:10 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:10 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:10 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:10 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:10 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:10 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:10 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:10 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:10 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:10 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:10 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:10 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:10 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:10 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:10 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:10 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:10 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:10 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:10 +0000
future timelineEntries limit: 100, date: 2017-02-09 23:33:10 +0000, entries: Optional(7)
timeline end: 2017-02-10 03:33:10 +0000
在这一点上,我杀死了应用程序......