How to use WatchConnectivity to send data from Phone to Watch (plus most common errors) - Part 1

Giada Ciotola
The Startup
Published in
4 min readJun 11, 2020

Connecting your Phone to your Watch to send data has never been easier! Follow this easy step-by-step guide, to discover how to pair them as well as what are the most common errors you might encounter.

For the porpouse of the article we will use the sendMessage(_:replyHandler:errorHandler:) method, which works also on the Simulator.

So how does it actually work? First of all create a project in Xcode that has both the iOS app and the Watch app (you can also add the Watch app to an existing project simply by adding a new target).

Now let’s get started with some code to pass a random array from the Phone to the Watch (full code at the end of the article)!

  1. For starters let’s create some nice labels and buttons on our Storyboards:

2. Then go to your ViewController and add import WatchConnectivity.

import WatchConnectivity

Now add let session = WCSession.default and then let’s activate it:

We will then need to add the WCSessionDelegate with its functions:

3. Let’s do the same for our Watch. First always type import WatchConnectivity, create a constant let session, activate it in the viewDidLoad, then add the delegate, but this time with also a didReceiveMessage function:

And it’s done! Well almost, because when then you run your app, you might not see your Watch Simulator at first and you’ll most likely get one of these 2 errors:

So now it’s the time to stop looking at your code and start messing around with your Simulators!

The first error says that the WCSession is not paired, while the second error states that WCSession counterpart app not installed.

But what does this all mean? In the first place, Xcode is telling you that if your iPhone simulator doesn’t have it’s own paired watch simulator there is no way to pass data!

So from Xcode, when going to choose a simulator, instead of picking an iPhone 11 or 8, click Add Additional Simulators and with the + go add the watch to the iPhone simulator of your choice.

Open both simulators, click the crown to see the main Watch interface with all the apps, and then start the pairing by clicking on the Watch app on your Phone (it should start automatically but sometimes you might need to close both Simulators and re-run the app).

Even if you already have an iPhone paired with a Watch, though, there is still something you’ll need to do: installing the app on the watch from the phone (always from the Watch app). Once that’s done folks, it’s really done!

Now when you run your code, you will be able to send your data from the iPhone to the Watch!

FULL CODE

Hope this was helpful! Feel free to ask any question.

Part 2 will be about sending data from the Watch to the iPhone, but this time let’s pass something more complex!

--

--

Giada Ciotola
The Startup

Born and raised in Italy. Graduated in Communication at Federico II. Apple Developer Academy Alumni. Currently iOS Developer at Beatcode.