How to track in iOS app if user has Apple Watch without watch extension? [closed]

你离开我真会死。 提交于 2021-02-07 10:29:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!