swiftapple-watchwatchconnectivity

Can I get information if this iPhone connected with Apple watch or not through WatchConnectivity?


I'm making Apple Watch App by Swift. I want to make a function which works depend on the existence of Phone-Watch connection. I'm using WatchConnectivity like below.

if (WCSession.isSupported()) {
        session = WCSession.default

        session?.delegate = self
        session?.activate()
    }

So this iPhone App needs to know if its owner has also this Apple Watch App and it's connected. Can I get that kind of information by Swift?


Solution

  • You can get this information from the WCSession object:

    session.isPaired // true when the iPhone is paired to an Apple Watch
    session.isWatchAppInstalled // true when the Watch app associated with the current iOS app is installed on the user’s Apple Watch
    

    Be aware that this only works when you activated a WCSession on your phone and your Watch app