简体   繁体   中英

Which method should I use to send data to Apple Watch and back?

I have an app which works similar to a to-do list. The user creates tasks which they want to be completed on their iPhone, and they are reminded at a desired time each day to complete that task. However, I am unsure which method of transferring data would be best for my app. I would like the Apple Watch to have the capability to at least view, and complete tasks. I would also like the data to be updated on both the Watch and iPhone when a task is completed, added, or deleted.

Should I use:

updateApplicationContext or transferUserInfo or sendMessage or any other method?

updateApplicationContext has the following advantages:

  • The transfer takes place in the background, even when the paired app is not open. The data gets transmitted, is held for your app, and then received once you open your app.

  • The transfer always contains the most recent state of your tasks. Any later transfer replaces any earlier transmitted application context data. You don't have to process multiple user info data, applying older data, change by change, which might be superseded by newer info further back in the queue.

Possible disadvantages of the other methods

transferUserInfo would queue and send multiple info about the list (or tasks). While that might be good on a task-by-task basis, you'd have to process the whole queue of changes to bring your entire list up to data, duplicating any work you did to apply the same changes on the paired device.

sendMessage would require interactive communication between two reachable apps, but you wouldn't generally be using the app on both devices at the same time.

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