简体   繁体   中英

How can I add background app refresh to swift WatchOs App

I have been looking for tutorials to help me to understand how I can add background app refresh for swift into my watch app, so that my Glance will have fairly up to date data (like the weather app).

So far I haven't found anything and wondered if anyone knew of any advice/examples/tutorials that might benefit me.

You could update your watch app with func updateApplicationContext(_ applicationContext: [String : AnyObject]) throws .

Use this method to transfer a dictionary of data items to the counterpart app. The system sends context data when the opportunity arises, with the goal of having the data ready to use by the time the counterpart wakes up. The counterpart's session delivers the data to the session:didReceiveUpdate: method of its delegate. A counterpart can also retrieve the data from the receivedApplicationContext property of its session. updateApplicationContext:error:

This method sends the data in a background task. When the data arrives you could save it in userDefault or in a class that could be read from your Glance, when your Glance willActivate is called just update the UI with the latest data that arrived in the context .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM