Apple Watch app detect if a apple watch is paired with the phone

时光总嘲笑我的痴心妄想 提交于 2019-12-21 04:20:49

问题


When the user opens the app on the phone is there a way to detect if the phone is paired/connected to a apple watch?


回答1:


There is no built-in method (at least in the WatchKit SDK) to determine if a Watch has been paired with an iPhone. A common strategy is to write a BOOL to a shared NSUserDefaults (using app groups) so that the iPhone knows that the Watch app has been run at least once. That's the technique I've used in my own app.




回答2:


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 :)




回答3:


If your code in your extension runs willActivate: on you controller then the Apple Watch is paired with the phone. Since you can't run any code on the actual Apple Watch there is no to know if the watch isn't paired with an iPhone.



来源:https://stackoverflow.com/questions/29661252/apple-watch-app-detect-if-a-apple-watch-is-paired-with-the-phone

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