问题
I want to know if my users have Apple Watch. If many user do, so I will develop Apple Watch application extension for my iOS app. Can I know if even watch is not paired?
回答1:
You should look at the WatchConnectivity framework. Especially, the isPaired method of WCSession should solve your problem.
In your iPhone app's application(didFinishLaunchingWithOptions:) method, set up and activate the WatchConnectivity session, since isPaired only returns a valid value for an activated session.
//Set up WatchConnectivity
if WCSession.isSupported() {
let session = WCSession.default()
session.delegate = self
session.activate()
}
In func session(activationDidCompleteWith) you can check if the iPhone is paired with an Apple Watch or not using this line of code:
let userHasAppleWatch = session.isPaired.
来源:https://stackoverflow.com/questions/44631060/how-to-track-in-ios-app-if-user-has-apple-watch-without-watch-extension