本文介绍了Watchkit 并发症和位置更新?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to write a complication that uses location data. I can get the location data in the complication controller but it never seems to work properly due to the results coming back asynchronously.

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

What is the best way to update a complication with location specific data? I'm thinking that it's not a good idea to get the location in the complication (even though you can).

推荐答案

您应该检索和缓存位置数据 在复杂数据源需要它之前.

You should retrieve and cache the location data before the complication data source needs it.

数据源类的工作是尽快为 ClockKit 提供任何请求的数据.数据源方法的实现应该是最少的.不要使用您的数据源方法从网络获取数据、计算值或做任何可能会延迟数据交付的事情.如果您需要为您的复杂功能获取或计算数据,请在您的 iOS 应用程序或 WatchKit 扩展的其他部分执行此操作,并将数据缓存在您的复杂功能数据源可以访问它的位置.您的数据源方法唯一应该做的就是获取缓存数据并将其放入 ClockKit 所需的格式.

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

You can retrieve location data on your phone, then use a watch connectivity session to transferCurrentComplicationUserInfo to your extension delegate. The extension delegate can cache the information for the complication controller, or extend the complication timeline with the new data.

这篇关于Watchkit 并发症和位置更新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 07:40