gpt4 book ai didi

swift - 并发症不会更新

转载 作者:搜寻专家 更新时间:2023-10-31 22:33:55 25 4
gpt4 key购买 nike

我有一个非常简单的随机数并发症。但是我的号码不会更新。每次我看 watch 都是一样的。仅当我重新安装复杂功能(重新安装 Apple Watch 应用程序)时,我才会收到一个新号码。

我已将更新设置为 1 秒。有人知道哪里出了问题吗?

func getCurrentTimelineEntryForComplication(complication: CLKComplication, withHandler handler: ((CLKComplicationTimelineEntry?) -> Void)) {
handler(CLKComplicationTimelineEntry(date: NSDate(), complicationTemplate: getTemplateForComplication(family: complication.family)!))
}

func getNextRequestedUpdateDateWithHandler(handler: (NSDate?) -> Void) {
handler(NSDate(timeIntervalSinceNow: 1))
}

func getPlaceholderTemplateForComplication(complication: CLKComplication, withHandler handler: (CLKComplicationTemplate?) -> Void) {
handler(getTemplateForComplication(family: complication.family))
}

func getTemplateForComplication(family family: CLKComplicationFamily) -> CLKComplicationTemplate? {
let bitcoinPrice = Double(arc4random_uniform(400))
switch family {
case .ModularSmall:
let template = CLKComplicationTemplateModularSmallSimpleText()
template.textProvider = CLKSimpleTextProvider(text: String(format: "%.2f", bitcoinPrice))
return template
case .ModularLarge:
let template = CLKComplicationTemplateModularLargeTallBody()
template.headerTextProvider = CLKSimpleTextProvider(text: "Bitcoin")
template.bodyTextProvider = CLKSimpleTextProvider(text: String(format: "%.2f €", bitcoinPrice))
return template
case .UtilitarianSmall:
let template = CLKComplicationTemplateUtilitarianSmallFlat()
template.textProvider = CLKSimpleTextProvider(text: String(format: "%.2f", bitcoinPrice))
return template
case .UtilitarianLarge:
let template = CLKComplicationTemplateUtilitarianLargeFlat()
template.textProvider = CLKSimpleTextProvider(text: String(format: " %.2f €", bitcoinPrice))
return template
default:
return nil
}
}

最佳答案

您的数据源丢失the methods that are responsible for handling the scheduled update .

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.

以下是您可以在计划的更新发生后重新加载时间线的方法:

// MARK: - Responding to Scheduled Updates

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

您还应该实现 requestedUpdateBudgetExhausted()

请记住,计划更新只能每 10 分钟发生一次;不可能每秒更新您的并发症。还要考虑更新过于频繁可能会耗尽您的更新预算:

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.

关于swift - 并发症不会更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34174337/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com