如何仅在手表醒着时更新手表并发症,以免耗尽每日预算 [英] How to update Watch Complication only when the watch is awake, to not use up the daily budget

查看:112
本文介绍了如何仅在手表醒着时更新手表并发症,以免耗尽每日预算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个保留2个布尔值的服务器.这些布尔值每15秒更改一次.

I have a server that keeps 2 booleans. These booleans change every 15 seconds.

每当我唤醒Apple Watch时,我都希望并发症显示当前状态.尽早用尽预算怎么办?

Whenever I wake my Apple Watch, I want the complication to show the current state. How can I do it withough exhausting the budget early on?

最好的方法是,每当我唤醒手表时,将最新状态提取到并发症中.我看到的唯一可能的方法是每15秒轮询一次服务器(直接或通过电话).问题是我很快就会用完所有分配的时间.

The best way would be to fetch the newest state into the complication whenever I wake my watch. The only possible way I see would be to poll the server (either directly or via my phone) every 15 seconds. The problem is that I'd soon use up all the allotted time.

如果我能在手表醒来时才使并发症更新,那将是很棒的.能做到吗?

It would be great if I could make the complication only update when the watch was woken up. Can that be done?

推荐答案

是否有一种方法可以不获取数据,除非您需要它?

Is there a way to not fetch data unless you need it?

否.

通过唤醒手表",您说的是通过与手表互动或举起手腕来激活手表.无论采用哪种方式,手表都可以唤醒到表盘或最后一次活动(由唤醒屏幕"设置控制).

By "waking the watch," you're speaking of activating the watch either by interacting with it, or by raising your wrist. Regardless of the manner, the watch can either wake to the watch face, or to the last activity (which is controlled by the Wake Screen setting).

  • 如果它唤醒了表盘,则它独立于您的应用程序,表扩展名或并发症控制器.没有通知可用于处理该情况.

  • If it wakes to the watch face, this is independent of your app, watch extension, or complication controller. There is no notification you can use to handle that scenario.

如果它是活动,则可能不是您的活动.如果这是您的活动,那么您所要做的就是在手表应用程序处于活动状态时停止更新.

If it wakes to an activity, it may not be your activity. If it were your activity, all you could do would be to stop updating when your watch app was active.

无论哪种方式,都没有偶然性,只能在手表醒着时更新并发症.

Either way, there is no contingency to only update the complication when the watch is awake.

如果您考虑所要询问的内容,则它与Apple的准则背道而驰,因为用户希望瞥一眼表盘并已经看到了当前的并发症数据.系统希望您在手表不醒时提供更新,因此当手表醒来时信息将立即可见.

更新并发症数据

可用的更新方法 ,这些将无法满足您的要求:

Of the available update approaches, these won't handle your requirements:

  • PKPushTypeComplication推送通知

  • PKPushTypeComplication push notifications

如果您不是一整天都在不断频繁地更新,那将是理想的选择.

This would be ideal, if you were not updating frequently and constantly throughout the day.

Apple对您从服务器发送的这种类型的推送次数设置每日限制.如果超出限制,则不会传递后续的推送.

Apple applies a daily limit to the number of pushes of this type that you send from your server. If you exceed the limit, subsequent pushes are not delivered.

  • 计划的自动更新

  • Scheduled automatic updates

    这里的问题是,计划的最小更新间隔为10分钟,因此在剩余的9-3/4分钟内您将没有当前的并发症信息.

    The issue here is that the minimum scheduled update interval is 10 minutes, so you wouldn't have current complication info for the remaining 9-3/4 minutes.

    计划的更新对于其数据在可预测的时间更改的应用程序很有用.当计划的更新发生时,ClockKit首先调用您的数据源的requestedUpdateDidBegin或requestedUpdateBudgetExhausted方法.

    Scheduled updates are useful for apps whose data changes at predictable times. When a scheduled update occurs, ClockKit calls the requestedUpdateDidBegin or requestedUpdateBudgetExhausted method of your data source first.

  • 这些方法可能会满足您的要求,但是您必须尝试一下,然后确定哪一个满足您的需求.

    These approaches might handle your requirements, but you'd have to try them and determine which one meets your needs.

    • 观看扩展程序和背景NSURLSession

    • Watch extension + background NSURLSession

    这可能会使电池消耗更多电量,但即使不在手机范围内也可以使用.

    This may place more of a drain on battery, but it would work even if not in range of the phone.

    通过WCSession transferCurrentComplicationUserInfo

    如果您在手机范围内,则更可能的方法是让手机(始终)轮询服务器,然后提供持续更新.

    If you're in range of your phone, the more likely approach would be for your phone to (always) poll your server, then provide constant updates.

    当您的iOS应用收到用于并发症的更新数据时,可以使用Watch Connectivity框架立即更新并发症. WCSession的transferCurrentComplicationUserInfo:方法将高优先级消息发送到您的WatchKit扩展,并根据需要唤醒以传递数据.接收到数据后,根据需要扩展或重新加载时间轴,以强制ClockKit从数据源中请求新数据.

    When your iOS app receives updated data intended for your complication, it can use the Watch Connectivity framework to update your complication right away. The transferCurrentComplicationUserInfo: method of WCSession sends a high priority message to your WatchKit extension, waking it up as needed to deliver the data. Upon receiving the data, extend or reload your timeline as needed to force ClockKit to request the new data from your data source.

    请注意,在iOS 10中,复杂性传输已编入预算.如果您执行大型任务,则此方法将不起作用每天的更新次数.

    Note that complication transfers are budgeted in iOS 10. This approach would not work if you were performing large numbers of updates per day.

    话虽如此,另一种方法是在服务器端监视这些布尔值,并仅在出现问题或更改时才发出通知.您没有确切解释这些布尔值表示什么,但是还有其他监视方法,可以避免您不得不不断地轮询服务器(从手机或手表).

    Having said all that, an alternate approach would be to monitor these booleans on the server side, and only send out a notification if there was a problem or change. You didn't explain exactly what these booleans indicate, but there are other approaches for monitoring, which would avoid you having to constantly poll a server (from your phone or watch).

    如果这不是一个选择,那么您确实应该考虑在手机上查看服务器数据,或者切换到更不频繁的更新间隔以解决复杂问题.苹果不鼓励这种频繁的更新,甚至他们自己(库存或天气)的复杂性也不是每分钟更新几次.

    If that's not an option, you really should consider either viewing the server data on your phone, or switching to a far less frequent update interval for your complication. Apple discourages such frequent updates, and even their own (stock or weather) complications are not updating several times a minute.

    更新:

    如果我只想在用户自己请求并发症时更新(怎么办),该怎么办?他一直都不对国家真正感兴趣.

    What if I only wanted to update the complication when user requested it himself(=clicked the complication)? He is not really interested in the state all the time.

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