-1

I'm wanting to be able to update my Apple Watch views if a user has both the Apple Watch app open and the iPhone app open as well. I know there is a WatchKit 1 question asked here, but I want to know if I could do this using WatchConnectivity.

Within my iOS app, I send a message:

if WCSession.isSupported() {
    // Set the session to default session singleton
    let session = WCSession.defaultSession()
    // Fire the message to watch
    NSLog("send message")

    session.sendMessage(["action": "messageAction"], replyHandler: nil, errorHandler: { (error) -> Void in
        // Display alert
        NSLog(error.description)
    })
}

But I keep getting the error:

Error Domain=WCErrorDomain Code=7007 "WatchConnectivity session on paired device is not reachable." UserInfo={NSLocalizedDescription=WatchConnectivity session on paired device is not reachable.}

To send messages from the iPhone to Apple Watch, is WatchConnectivity sendMessage the correct method to use?

Community
  • 1
  • 1
Mike Walker
  • 2,944
  • 8
  • 30
  • 62

1 Answers1

2

It's only the "correct" method if you are looking to interactively communicate with a reachable device.

But you haven't shown where you set your session delegate or activated the session:

let session = WCSession.defaultSession()
session.delegate = self
session.activateSession()

You may also want to add some checks to ensure that a watch is paired (session.paired), that the watch app is installed (session.watchAppInstalled), and that the watch is actually reachable (session.reachable) before trying to interactively communicate with it, to make your app more robust.

See this guide for more details.

You could also choose to fall back on a non-interactive (background) method to queue messages for your app until it is open and can receive them.