当用户在手机上打开应用时,有没有办法检测手机是否与Apple Watch配对/连接?
当用户在手机上打开应用时,有没有办法检测手机是否与Apple Watch配对/连接?
所以在WatchOS 2上是可以实现的!
您需要在iPhone端进行以下操作:
首先:
import WatchConnectivity
那么:
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
}
}
我希望它能对你有所帮助 :)
if session.paired
会在用户在手表上收到对话框之前返回true,因此无论用户是否接受该应用程序都没有关系。 - Sti在WatchKit SDK中,没有内置的方法可以确定Watch是否已经与iPhone配对。一种常见的策略是将BOOL写入共享的NSUserDefaults(使用应用程序组),以便iPhone知道Watch应用程序至少运行了一次。这是我自己应用程序中使用的技术。