如何检查iPhone和苹果手表是否连接

有没有什么办法可以通知Apple Watch用户iPhone现在已经超出范围,以及何时回到范围内。 我们如何在手表扩展中做到这一点。

提前致谢。

所以在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 } } 

我希望它会帮助你:)

随着watchOS 2.0,你可以。 要做到这一点,如果您希望Apple Watch收到通知,您可以将其添加到您的ExtensionDelegate中:

 func watchKitSetup() { if (WCSession.isSupported()) { let session = WCSession.defaultSession() session.delegate = self session.activateSession() // In your WatchKit extension, the value of this property is true when the paired iPhone is reachable via Bluetooth. // On iOS, the value is true when the paired Apple Watch is reachable via Bluetooth and the associated Watch app is running in the foreground. // In all other cases, the value is false. if session.reachable { } } } func applicationDidFinishLaunching () { self.watchKitSetup() } // Called when session.reachable value changes, such as when a user wearing an Apple Watch gets out of range of their iPhone. func sessionReachabilityDidChange(session: WCSession) { if session.reachable { } } 

你也应该添加WCSessionDelegate到你的ExtensionDelegate。

从正式的angular度来看,苹果没有给出任何迹象表明如何处理。

但是,由于操作系统在没有应用程序参与的情况下处理了配对和通信区域,几乎可以肯定的是,任何关于手表(和电话端)连接问题的通知都将由Watch OS来处理。 我的猜测是,用户将有机会解决连接丢失问题,或者退出Watch应用程序,如果他们不能。 从开发人员的angular度来看,很可能我们的应用程序无法区分无法解决的连接丢失和用户正常退出应用程序,同时向Watch Extension发送相同的通知,但这只是一个猜测。

值得注意的是,目前的Watch应用程序并没有运行第三方开发者代码,只是一个UI,所以即使连接丢失也不会导致数据丢失。 如果操作系统由于与手表连接中断而使手表扩展程序(在iPhone上运行)退出,它仍然可以执行其通常的数据存储和清理。

从目前的知识来看,这可能是不可能的。

从苹果的WatchKit应用程序架构

select场景后,WatchKit会告诉配对的iPhone启动您的WatchKit扩展,并创buildpipe理该场景所需的对象。 当场景完全configuration后,它会显示在Apple Watch上。 WatchKit应用程序和WatchKit扩展之间的信息传输在幕后透明地进行。

这意味着,代码在iPhone上执行。 如果iPhone遥不可及,则无法在手表上运行应用程序。

您可以在WCSession文档中find所有连接状态更改通知。