Watchkit 并发症和位置更新?

Watchkit Complication and location updates?

我正在尝试编写一个使用位置数据的复杂功能。我可以在并发症控制器中获取位置数据,但由于结果异步返回,它似乎永远无法正常工作。

用位置特定数据更新复杂功能的最佳方法是什么?我认为在并发症中获取位置不是一个好主意(即使你可以)。

您应该检索并缓存位置数据 before the complication data source needs it

The job of your data source class is to provide ClockKit with any requested data as quickly as possible. The implementations of your data source methods should be minimal. Do not use your data source methods to fetch data from the network, compute values, or do anything that might delay the delivery of that data. If you need to fetch or compute the data for your complication, do it in your iOS app or in other parts of your WatchKit extension, and cache the data in a place where your complication data source can access it. The only thing your data source methods should do is take the cached data and put it into the format that ClockKit requires.

您可以在 phone 上检索位置数据,然后使用手表连接会话 transferCurrentComplicationUserInfo 到您的分机代理。扩展委托可以为复杂控制器缓存信息,或者用新数据扩展复杂时间线。