requestedUpdateDidBegin 只调用了一次

requestedUpdateDidBegin just called once

我以为下面的代码会每5分钟请求一次新数据,但是模拟器上没有更新。

func getNextRequestedUpdateDateWithHandler(handler: (NSDate?) -> Void) {
    print("update")
    handler(NSDate(timeIntervalSinceNow: NSTimeInterval(5*60))
}

我需要为此进行一些项目设置吗?

我已经使用 Xcode 7.1.1 和 7.2 Beta 4

对其进行了测试

您必须 handle the scheduled update 发生时,否则 ClockKit 将停止请求新的时间线条目:

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.

您的数据源可能缺少可选的 requestedUpdateDidBegin 方法。下面是一个示例,说明如何在发生更新时延长时间线:

// MARK: - Responding to Scheduled Updates

func requestedUpdateDidBegin() {
    let server=CLKComplicationServer.sharedInstance()

    for complication in server.activeComplications {
        server.extendTimelineForComplication(complication)
    }
}

请注意,最小更新间隔为 10 分钟,因此您不会像预期的那样每 5 分钟被调用一次。频繁更新也可能会耗尽您的更新预算。 Apple 建议开发者:

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.