18

In my app,

I need to find if my phone is paired with a apple watch and get some information about the paired watch like its name. I tried reading the documentation but I couldn't seem to find any thing specific to my use case.

Any help is appreciated.

Vamsi Krishna
  • 585
  • 6
  • 17

3 Answers3

17

So since WatchOS 2 that is possible !

You have to do on iPhone side :

First :

import WatchConnectivity

Then :

   if WCSession.isSupported() { // check if the device support to handle an Apple Watch
        let session = WCSession.default()
        session.delegate = self
        session.activate() // activate the session

        if session.isPaired { // Check if the iPhone is paired with the Apple Watch
                // Do stuff
        }
    }

I hope It would help you :)

BilalReffas
  • 8,132
  • 4
  • 50
  • 71
6

The best you can do is write to a shared NSUserDefaults value the first time the user opens your WK app, then check for that value in your iOS app. Beyond that there's no info you can get.

bgilham
  • 5,909
  • 1
  • 24
  • 39
  • this seems ok! But if want to have a alternative behavior in my iphone app based on whether apple watch is connected or not then the above solution might not be of help! – Vamsi Krishna Apr 09 '15 at 17:28
3

The idea is taken from @BilalReffas answer, but in WatchOS versions greater than 2.1 activate() method is asynchronous, so the offered solution won't work (it always returns false, even if watch is connected)

Firstly import SDK

import WatchConnectivity

Then implement session activation request

if WCSession.isSupported() { // check if the device support to handle an Apple Watch
    let session = WCSession.default
    session.delegate = self
    session.activate() // activate the session
}

Then implement methods from WCSessionDelegate

func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) {
    if activationState == .activated && session.isPaired { // Check if the iPhone is paired with the Apple Watch
        // Do stuff
    }
}
Accid Bright
  • 592
  • 5
  • 17