The biggest value-add with WatchOS 2 is something the user will not see, but something that will make your WatchOS app usable the most: WatchConnectivity.
WatchConnectivity is the new WatchOS 2 framework to use for transferring data between your Watch App and your iOS device. The key part of WatchConnectivity is that it enables your Watch App to have the necessary data before the user even decides to look at your Complication or Glance or App. That means that when the user looks at your app or glance or complication, they will expect to see the data they’re looking for right away, without any silly spinner.
After all, the Apple Watch is an on-the-go device. While users might be willing to look at your super cute refresh animation on your iOS app for a second or two, they will not tolerate it on the go. Imagine if every time the user needed to see the time on their regular watch, they saw a spinner first for a second. That would be super silly, and it will be just as silly if your app does this.
Don’t worry though. WatchConnectivity does most of the work for you, so it’s really not that hard to implement your app in a way where transferring data to your Watch App is a seamless process your user does not need to know anything about.
So let’s dive in! WatchConnectivity has two parts – background transfers and interactive messaging. I’ll go through each one of these in a lot more detail in future tutorials, but here is an overview when thinking about which data transfer model you need to use:
Background Transfers are for information your iOS or Watch App do not need immediately. Sure, it’ll be there when the user raises their wrist to see the latest data from your app on the watch, but they don’t need the data until then.
Since background transfers applies to data that is not needed immediately, Apple decides when the best time for these background data transfers are – likely based on things like battery life, network connectivity, usage patterns, etc.
There are three ways to transfer data between your iOS and Watch app in the background:
Use Application Context when your Watch App only needs to display the latest information available. For example, if your Glance shows the game score, the user doesn’t care that the score was 4-2 two minutes ago. They only care that the current score is 4-4. Another example for this use-case is a transportation app – your user doesn’t care that the last bus left the station five minutes ago – they only care about when the next bus will be arriving.
So the way Application Context works is that it queues up a piece of data, and if there’s a brand new piece of data available before the data is transferred, the original (old) data is replaced by the new data, which is then transferred over unless it is replaced yet again by an even newer piece of data.
User Info is for when you need to make sure that all your data is transferred (not just the latest like with Application Context). User Info data is queued up for delivery in a FIFO (first-in-first-out) order, so nothing is overwritten.
One examples for when you might want to use this is in a text messaging app – when the last message is just as important as the first to see the full conversation and context. Or if the user updated a few pieces of their profile information and all the changes need to be synced to the Watch profile.
This is self-explanatory. Use File Transfer to transfer files, such as images or plists, between your iOS and your Watch app. The nice thing about file transfer is that you can include a meta-data dictionary – which could include your file’s name and data – which you can then use to order your images, for example.
Use Interactive Messaging to transfer data between your iOS and Watch app live! One great example of this was done in the Flappy Bird app for the Watch and iPhone – the user taps on the Watch, but the bird flies on the phone. The button click taps are transferred to the phone using Interactive Messaging.
One caveat is that Interactive Messaging requires the iPhone to be in “reachable” state. According to Apple’s documentaion comments:
“Reachability in the Watch app requires the paired iOS device to have been unlocked at least once after reboot.”
I love this chart in Kristina Thai’s WatchConnectivity post for distinguishing between the different transfers:
Also check out Curtis Herbert’s Watch OS 2 observations at the bottom of his Getting Data to Your WatchOS 2 App post.