stonycis
stonycis

Reputation: 476

Is there a way to detect if an Apple Watch is paired with an iPhone?

I want to know if there's an API available that shows the availability of an Apple Watch. I don't want to write an Apple Watch App yet. I want to do some analysis to see what percentage of actual users have an Apple Watch, before investing time to develop a watch version (if possible, of course).

Upvotes: 4

Views: 2389

Answers (3)

José
José

Reputation: 3164

Swift 5

import WatchConnectivity

Then:

final class WatchSessionManager: NSObject {

    private override init() {}

    static let shared = WatchSessionManager()

    func setup() {
        guard WCSession.isSupported() else {
            return
        }
        let session = WCSession.default
        session.delegate = self
        session.activate()
    }
}

extension WatchSessionManager: WCSessionDelegate {

    func sessionDidBecomeInactive(_ session: WCSession) {}

    func sessionDidDeactivate(_ session: WCSession) {}

    func session(
        _ session: WCSession, 
        activationDidCompleteWith activationState: WCSessionActivationState, 
        error: Error?
    ) {
        print("Apple Watch is paired: \(session.isPaired)")
    }

}

Upvotes: 2

BilalReffas
BilalReffas

Reputation: 8328

So on 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.defaultSession()
        session.delegate = self
        session.activateSession() // activate the session

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

I hope It would help you :)

Upvotes: 6

agy
agy

Reputation: 2854

The answer is yes but you have to support watchOS 2 and iOS9 to do it. You need to check the property pairedfrom WCSession class.

You can find all the information at Watch Connectivity Framework Reference. I also recommend to watch this video from WWDC 2015 and read this tutorial

Upvotes: 4

Related Questions