Reputation: 476
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
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
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
Reputation: 2854
The answer is yes but you have to support watchOS 2 and iOS9 to do it.
You need to check the property paired
from 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