Watchkit Complication and location updates?

徘徊边缘 提交于 2019-12-12 06:02:18

问题


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).


回答1:


You should retrieve and cache the location data 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.

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.



来源:https://stackoverflow.com/questions/34712889/watchkit-complication-and-location-updates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!