简体   繁体   English

Apple Watch应用可检测苹果手表是否与手机配对

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

当用户在手机上打开应用程序时,有没有办法检测手机是否配对/连接到苹果手表?

So on WatchOS 2 that is possible ! 所以在WatchOS 2上这是可能的!

You have to do on iPhone side : 你必须在iPhone方面做:

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 :) 我希望它会帮助你:)

There is no built-in method (at least in the WatchKit SDK) to determine if a Watch has been paired with an iPhone. 没有内置方法(至少在WatchKit SDK中)来确定Watch是否已与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. 一个常见的策略是将BOOL写入共享的NSUserDefaults(使用应用程序组),以便iPhone知道Watch应用程序至少运行过一次。 That's the technique I've used in my own app. 这是我在自己的应用程序中使用的技术。

If your code in your extension runs willActivate: on you controller then the Apple Watch is paired with the phone. 如果您的扩展程序中的代码运行willActivate:在您的控制器上,则Apple Watch将与手机配对。 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. 由于您无法在Apple Watch上运行任何代码,因此无法确定手表是否未与iPhone配对。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM