我有一个Apple Watch复杂功能,可以正确初始化并显示我期待的数据。但是,当我的getNextRequestedUpdateDateWithHandler方法返回的NSDate触发刷新时,我的委托中唯一再次调用的方法是getNextRequestedUpdateDateWithHandler方法(我在每个方法中设置断点来确定这一点)。我希望在请求的更新日期发生时调用requestedUpdateDidBegin,但似乎并非如此。有谁知道是什么原因引起的?这是我的代码:
class ComplicationController: NSObject, CLKComplicationDataSource {
/// Provide the time travel directions your complication supports (forward, backward, both, or none).
func getSupportedTimeTravelDirectionsForComplication(complication: CLKComplication, withHandler handler: (CLKComplicationTimeTravelDirections) -> Void) {
handler(.Backward)
}
/// Depending on which time travel directions you support, you will be asked for the start/end dates of your timeline (or both, or neither).
/// The start/end dates will determine at what point during time travel we dim out your data to indicate that the timeline does not continue in this direction.
/// Timeline entries after the timeline end date or before the timeline start date will not be displayed.
func getTimelineStartDateForComplication(complication: CLKComplication, withHandler handler: (NSDate?) -> Void) {
let calendar = NSCalendar.currentCalendar()
let now = NSDate()
var startDate: NSDate? = nil
var interval: NSTimeInterval = 0
calendar.rangeOfUnit(NSCalendarUnit.WeekOfMonth, startDate: &startDate, interval: &interval, forDate: now)
handler(startDate)
}
func getTimelineEndDateForComplication(complication: CLKComplication, withHandler handler: (NSDate?) -> Void) {
handler(NSDate())
}
/// Indicate whether your complication's data should be hidden when the watch is locked.
func getPrivacyBehaviorForComplication(complication: CLKComplication, withHandler handler: (CLKComplicationPrivacyBehavior) -> Void) {
// Since this is showing health data, we want to secure this when the device is locked.
handler(.HideOnLockScreen)
}
/// Indicate your complication's animation behavior when transitioning between timeline entries.
func getTimelineAnimationBehaviorForComplication(complication: CLKComplication, withHandler handler: (CLKComplicationTimelineAnimationBehavior) -> Void) {
handler(.Always)
}
/// Provide the entry that should currently be displayed.
/// If you pass back nil, we will conclude you have no content loaded and will stop talking to you until you next call -reloadTimelineForComplication:.
func getCurrentTimelineEntryForComplication(complication: CLKComplication, withHandler handler: (CLKComplicationTimelineEntry?) -> Void) {
// ... custom entry code
handler(currentTemplate)
}
/// The owning complication will use these methods to extend its timeline backwards or forwards.
/// @param date The date of the first/last entry we already have. Return the batch of entries before/after this date.
/// @param limit Maximum number of entries to return.
func getTimelineEntriesForComplication(complication: CLKComplication, beforeDate date: NSDate, limit: Int, withHandler handler: ([CLKComplicationTimelineEntry]?) -> Void) {
//... custom entry code
handler(templates)
}
func getTimelineEntriesForComplication(complication: CLKComplication, afterDate date: NSDate, limit: Int, withHandler handler: ([CLKComplicationTimelineEntry]?) -> Void) {
handler([CLKComplicationTimelineEntry]())
}
/// Return the date when you would next like to be given the opportunity to update your complication content.
/// We will make an effort to launch you at or around that date, subject to power and budget limitations.
func getNextRequestedUpdateDateWithHandler(handler: (NSDate?) -> Void) {
// Refresh in 30 minutes
let refreshDate = NSDate().dateByAddingTimeInterval(60*30)
handler(refreshDate)
}
/// This method will be called when you are woken due to a requested update. If your complication data has changed you can
/// then call -reloadTimelineForComplication: or -extendTimelineForComplication: to trigger an update.
func requestedUpdateDidBegin() {
let complicationServer = CLKComplicationServer.sharedInstance()
for complication in complicationServer.activeComplications {
complicationServer.reloadTimelineForComplication(complication)
}
}
/// This method will be called when we would normally wake you for a requested update but you are out of budget. You can can
/// trigger one more update at this point (by calling -reloadTimelineForComplication: or -extendTimelineForComplication:) but
/// this will be the last time you will be woken until your budget is replenished.
func requestedUpdateBudgetExhausted() {
let complicationServer = CLKComplicationServer.sharedInstance()
for complication in complicationServer.activeComplications {
complicationServer.reloadTimelineForComplication(complication)
}
}
/// When your extension is installed, this method will be called once per supported complication, and the results will be cached.
/// If you pass back nil, we will use the default placeholder template (which is a combination of your icon and app name).
func getPlaceholderTemplateForComplication(complication: CLKComplication, withHandler handler: (CLKComplicationTemplate?) -> Void) {
//... custom template code
handler(template)
}
}
答案 0 :(得分:3)
setup'
from /Users/vbaker/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.0/lib/rspec/core/runner.rb:88:in
是您的并发症数据源准备提供数据的最新日期。如果你的结束日期已经过去,这意味着两件事:
随着时间表的结束,最新的时间表输入将变暗。
并发症服务器会意识到,通过endDate请求条目是没有意义的,因为可能不存在将来的条目。在这种情况下,正如您所注意到的那样,并发症服务器只会要求新的更新日期。
并发症服务器使用72小时滑动窗口,确保在任何方向上行走24小时。
即使你不支持前进时间旅行,你也应该确保未来run'
from /Users/vbaker/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.0/lib/rspec/core/runner.rb:41:in
有几个原因。
如果您不希望当前条目变暗,则在重新加载时间轴之前不得达到结束日期。
并发症服务器必须知道您的数据源可能会被要求提供其他条目,因为您的时间表仍然是最新的。
每次重新加载时间线时,都会要求新的开始和结束日期。您的结束日期永远不会在遥远的未来,因为最多它将每30分钟更新一次,但如果您的每日预算因频繁更新而耗尽,则它应该仍然是未来的一天。
顺便说一下,the complication server会考虑时间旅行边界日期,以确定是否应将条目添加到时间轴。
<top (required)>' from /Users/vbaker/.rbenv/versions/2.2.2/bin/rspec:23:in
构建时间轴时,请勿在此日期之前创建任何条目。这样做是浪费时间,因为这些条目永远不会显示。
如果您提供的信息可以追溯到一周开始,您可能希望避免在时间旅行边界之外创建条目,以免耗尽预算。