1

目前,我的代码不起作用。我仍然需要手动刷新它。我希望并发症每 12 小时自动更新一次。

func getTimelineStartDate(for complication: CLKComplication, withHandler handler: @escaping (Date?) -> Void) {

    let date = Calendar.current.startOfDay(for: Date())
    print("timeline start date :\(date)")
    handler(date)
}

func getTimelineEndDate(for complication: CLKComplication, withHandler handler: @escaping (Date?) -> Void) {
    var  date = Calendar.current.startOfDay(for: Date())
    date = Calendar.current.date(byAdding: .day, value: 2, to: date)!
    print("timeline end date:\(date)")
    handler(date)
}

func getNextRequestedUpdateDate(handler: @escaping (Date?) -> Void){
    handler(Date(timeIntervalSinceNow: 60*60*12))


}
4

2 回答 2

1

您可以使用以下函数来为您的复杂功能填充数据。

func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -> Void) {
    // Call the handler with the current timeline entry
    handler(nil)
}

func getTimelineEntries(for complication: CLKComplication, before date: Date, limit: Int, withHandler handler: @escaping ([CLKComplicationTimelineEntry]?) -> Void) {
    // Call the handler with the timeline entries prior to the given date
    handler(nil)
}

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
    handler(nil)
}

请参阅watchOS 应用程序编程指南

于 2017-05-22T08:51:45.010 回答
1

似乎数据源方法没有实现。它需要为刷新实现。

在计划更新开始时,ClockKit 会调用 requestedUpdateDidBegin 或 requestedUpdateBudgetExhausted 方法,具体取决于您的并发症的时间预算状态。如果要将数据添加到时间线,则必须实现其中一种或两种方法。您对这些方法的实现应根据需要扩展或重新加载您的并发症的时间线。当您这样做时,ClockKit 会从您的数据源请求新的时间线条目。如果您不扩展或重新加载您的时间线,ClockKit 不会要求任何新的时间线条目。

func requestedUpdateDidBegin() {
    let server=CLKComplicationServer.sharedInstance()
    for complication in server.activeComplications {
        server.reloadTimelineForComplication(complication)
    }
}

有关更多信息,请查看

于 2017-05-23T08:54:57.117 回答