watchOS-显示并发症的实时出发数据 [英] watchOS - Show realtime departure data on complication

查看:173
本文介绍了watchOS-显示并发症的实时出发数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个公共交通应用,其中包含火车的实时出发数据. 我想添加一个复杂的功能,以显示下一列火车的发车时间.

I have an public transport app with realtime departure data for trains. I would like to add a complication that shows the departure time of the next train.

是否可以显示(或刷新)复杂情况下的实时数据?例如,显示到X站3分钟".数据可能每分钟都会更改,具体取决于来自公共交通API的信息.

Is it possible to show (or refresh) realtime data on a complication? For example, showing "3 min. to station X." The data could change every minute, based on info that comes from the public transport API.

如何在watchOS 2或watchOS 3上完成此操作?

How should I accomplish this on watchOS 2 or watchOS 3?

我知道ETA应用程序会以复杂的方式显示出行时间,但我不确定它们是如何实现的.

推荐答案

是否可以进行实时更新?

  • 并发症并非旨在显示实时数据.频繁的更新会影响能效并影响电池(在手表和手机上).

    Are realtime updates possible?

    • Complications aren't designed to show realtime data. Frequent updates can affect energy efficiency and impact the battery (on both watch and phone).

      为最大程度地减少功耗,ClockKit要求您提供尽可能多的数据,然后将其缓存并在需要时进行渲染.

      To minimize power usage, ClockKit asks you to provide as much data as you have available and then caches the data and renders it when needed.

    • 虽然没有可以重复加载并发症时间表的固定次数,但并发症数据源要遵守每日执行时间预算.

    • While there is no fixed number of times a complication timeline can be reloaded, the complication data source is subject to a daily execution time budget.

      如果您的应用程序数据经常更改,则可能难以提供足够的数据来复杂显示.更糟糕的是,如果您过于频繁地刷新并发症数据,则可能会超出执行时间预算,并且直到第二天才可能更新并发症.

      If your app’s data changes frequently, it might be difficult to provide enough data to display in a complication. Worse, if you refresh your complication data too frequently, you may exceed your execution time budget and your complication might not be updated until the following day.

    • 一旦每日预算用尽,请致电 reloadTimeline (和 extendTimeline )无用.

    • Once the daily budget is exhausted, calls to reloadTimeline (and extendTimeline) do nothing.

      如果您的并发症已经超出了执行时间所分配的每日预算,则对该方法的调用无济于事.谨慎地调用此方法.

      If your complication has already exceeded its allotted daily budget for execution time, calls to this method do nothing. Call this method sparingly.

      • You can use a CLKRelativeDateTextProvider to create a formatted relative time that can change on a minute-by-minute basis.

      CLKRelativeDateTextProvider对象创建一个格式化的字符串,该字符串传达当前日期和您指定的日期之间的时间差.您可以使用相对日期文本提供程序来高效地实现计时器或其他相对时间值.不要使用多个时间轴条目来复制倒数计时器,而使用相对日期文本提供程序创建一个时间轴条目.当用户查看钟面时,ClockKit会自动更新并发症中的相对时间值,并提供最新的时间信息.

      A CLKRelativeDateTextProvider object creates a formatted string that conveys the difference in time between the current date and a date that you specify. You use a relative date text provider to implement timers or other relative time values in an efficient way. Instead of using multiple timeline entries to replicate a countdown timer, create a single timeline entry with a relative date text provider. When the user views the clock face, ClockKit automatically updates the relative time value in your complication, providing up-to-date time information.

      • 您可以使用并发症推送更新(从远程服务器或从iOS 10中的手机本地使用).

      • You could use a complication push update (either from a remote server, or locally from the phone in iOS 10).

      每天最多只能进行50次并发症推送更新.

      There is a limit of 50 complication push updates per day.

      您可以在手机上获取数据并使用 transferCurrentComplicationUserInfo .

      You could fetch data on the phone and use transferCurrentComplicationUserInfo.

      在watchOS 2中,这仅受每日预算的限制.在watchOS 3中,现在每天最多只能进行50次传输.

      In watchOS 2, this was only subject to the daily budget. In watchOS 3, this is now limited to 50 transfers per day.

      请参见 transferCurrentComplicationUserInfo更适合于并发症更新?了解更多详情.

      See Is transferCurrentComplicationUserInfo more suitable for complication update? for more details.

      在watchOS 2中,您可以使用 getNextRequestedUpdateDate 安排下次更新并发症.

      In watchOS 2, you could use getNextRequestedUpdateDate to schedule the next time to update your complication.

      这种情况发生的频率不能超过每十分钟一次.

      This can't occur more often than every ten minutes.

      请注意,应将watchOS 3应用程序升级为使用后台刷新应用程序任务.主要好处是,后台任务不仅可以更新您的并发症,还可以做更多的事情.他们还可以处理数据获取,数据到达后更新模型以及更新停靠快照.

      最后,您可以安排手动更新.在watchOS 3中,推荐的方法是通过后台刷新应用程序任务.

      Finally, you can schedule a manual update. In watchOS 3, the recommended way to do this would via a background refresh app task.

      任务预算每小时允许执行4个任务.有关更多详细信息,请参见 scheduleBackgroundRefresh .

      The task budget permits 4 tasks per hour. See scheduleBackgroundRefresh for more details.

      请注意,后台刷新应用程序任务不得使用超过10%的CPU.

      • 208 What's New in watchOS 3 introduces some of these topics.

      804 设计出色的Apple Watch体验讨论了何时以及为什么更新您的手表应用.

      804 Designing Great Apple Watch Experiences discusses when and why to update your watch apps.

      218 使手表应用保持最新状态提供了详细信息有关使用后台任务更新并发症,应用程序和停靠快照的信息.

      218 Keeping Your Watch App Up to Date provides details about using background tasks to update your complication, app, and dock snapshot.

      如会谈中所述,您应该在需要时安排更新时间.

      As mentioned in the talks, you should schedule your updates around the times when they would be needed.

      在您的用例中,示例仅在运行公共交通的情况下,并且仅在定期排定的出发时间受延误影响的情况下.

      For your use case, examples would be only when public transit is running, and only when the regularly scheduled departure times would be affected by a delay.

      Apple提供了 WatchBackgroundRefresh 示例代码如何使用WKRefreshBackgroundTask在后台更新WatchKit应用.

      Apple provides WatchBackgroundRefresh sample code demonstrating how to use WKRefreshBackgroundTask to update WatchKit apps in the background.

      要更新后台任务中的任何活动并发症,您只需添加代码即可重新加载(或延长)时间轴:

      To update any active complication within a background task, you would simply add code to reload (or extend) the timeline:

      let complicationServer = CLKComplicationServer.sharedInstance()
      
      for complication in activeComplications {
          complicationServer.reloadTimelineForComplication(complication)
      } 
      

      这篇关于watchOS-显示并发症的实时出发数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆