2

I'm writing an iPhone and Watch app. I'm planning on supporting the ability to pair multiple watches to the phone.

The iPhone and Watch app will both read and write to a Core Data datastore, and I'll use WatchConnectivity to keep them in sync (using transferUserInfo:). The user will write/dictate something on one device, and it will appear on the other.

I'm struggling to figure out how to support multiple watches. Given the following scenario:

  • User is using Phone/WatchA
    • Over the course of the day, user adds 10 items
  • End of the day, they switch to WatchB

How will WatchB get in sync with the Phone/WatchA?

  • Will WKSession automatically replay the transferUserInfo calls that were made when WatchA was paired?
  • Do I need to somehow keep track of everything WatchB needs and replay everything myself?
  • Do I just send the entire sqlite database using the transferFile API (that seems a bit much)?
djibouti33
  • 12,102
  • 9
  • 83
  • 116

1 Answers1

5

Will WKSession automatically replay the transferUserInfo calls that were made when WatchA was paired?

No it won't. The data only gets transferred to the paired watch.

When you switch back to the other watch, you'd have to specifically arrange to update its store.

Do I need to somehow keep track of everything WatchB needs and replay everything myself?

In short, yes, if that's the approach that you take.

One edge case would be if the user replaces an old/broken watch with a new/replacement watch, yet didn't unpair the old one. You wouldn't want to keep track of a growing number of changes for a watch that won't ever be paired again.

You'd also have to handle the case where the user upgrades their phone, and pairs the existing watches with the new phone. Your device tracking and syncing should continue to work across a different device pair.

Do I just send the entire sqlite database using the fileTransfer API (that seems a bit much)?

It really depends on the size of the database, versus the complexity of journaling and syncing data between three or more stores.

What new features would help me keep my watch up to date?

If you must maintain multiple stores, you should definitely take advantage of the background refresh task feature in watchOS 3 to keep your watch(es) up-to-date before the user launches the app, so the user won't have to wait for anything to sync.

This answer might be helpful, even if you aren't using complications.

What are my other options?

Apple recommends that you design everything around the different ways of interacting with the devices. A user might just want to glance at the watch for a couple of seconds to review some items, but rely on the phone for more complex tasks.

In that case, you could maintain a single store on the iPhone, and transfer any needed data from the iPhone to be displayed on the watch. If anything changes, push the updated data back to the phone.

A "Handoff" approach works best, where the phone and the watch know what the most recent items were, and the user can switch between the phone and the watch during the day.

Of course, this is contingent on whether the watch must operate independently or not while out-of-range of the phone.

Community
  • 1
  • 1
  • Wonderfully detailed answer, thank you. I think I need to rethink my watch strategy, as it seems, for my needs, way to cumbersome to build out a system that can reliably sync between x number of paired devices. – djibouti33 Jul 25 '16 at 22:06
  • If you're open to storing data objects in the cloud, CloudKit was designed to handle synchronization between devices. I wouldn't encourage anyone to try to roll their own system. It's very complex, and you'll end up with a lot of technical debt. Let Apple or someone else manage those intricacies! :) –  Jul 25 '16 at 22:37
  • that's a really good point, and one i hadn't considered. i am actually planning on cloud kit integration for my v2 (want to focus on shipping a v1 as my main priority), so that might be a good time to bring native cloud kit support (and thus sync) to the phone and watch. in the meantime, based on your answer, i reduced the complexity and functionality of the watch app, which will allow me to get out the door faster. at this point, multiple watches is an edge case anyways, so I'd hate for that to hold me up. – djibouti33 Jul 26 '16 at 02:29