简体   繁体   English

watchOS 2.2应用程序如何确定其配对的iPhone是否已切换到另一款Apple Watch?

[英]How can watchOS 2.2 app determine if its paired iPhone has switched to another Apple Watch?

I'm trying to support the new feature for pairing with multiple watches in my iOS 9.3/watchOS 2.2 app. 我正在尝试在iOS 9.3 / watchOS 2.2应用程序中支持与多个手表配对的新功能。 It seems to be working well, except that I can't figure out how the watchOS app can determine if the paired iPhone has been switched to another Apple Watch. 它似乎运行良好,除了我无法弄清楚watchOS应用程序如何确定配对的iPhone是否已切换到另一个Apple Watch。

The docs say that the WCSession stays activated from the perspective of the WatchKit extension throughout the switching lifecycle, and from my testing in Xcode, it seems that the watch session reports that the iPhone is also reachable even when the phone has been switched to another watch. 文档说, WCSession撑从整个开关周期的WatchKit延伸的角度被激活,并从我在Xcode的测试,似乎手表会议报告说,iPhone也可到达,即使电话已经切换到另一个手表。

I don't currently have multiple watches to be able to check if the behavior is the same on an actual device. 我目前没有多个手表能够检查实际设备上的行为是否相同。

A specific answer to your question: 您问题的具体答案:

The fact that the watch is no longer connected is not readily apparent, as all transfer methods can be used, including immediate messaging . 手表不再连接的事实并不明显,因为可以使用所有传输方法, 包括即时消息传递 Transfers are simply deferred until the user switches back to that watch. 转移只是推迟到用户切换回该手表。

Since an unconnected watch can still initiate transfers to its paired iPhone, you would likely have to implement some sort of handshake or timeout detection, and see if the phone fails to respond in time. 由于未连接的手表仍然可以启动到其配对的iPhone的转移,您可能必须实施某种握手或超时检测,并查看手机是否未能及时响应。

My findings: 我的发现:

It seems that the unconnected watch is not meant to know that the user has switched to a different watch. 似乎未连接的手表并不意味着用户已经切换到不同的手表。 As you pointed out, the watch app's session is still active, and the watch (simulator) still reports that phone is reachable. 正如您所指出的,手表应用程序的会话仍处于活动状态,手表(模拟器)仍然报告手机可以访问。

An unconnected watch app can continue to use all transfer methods including interactive messaging (although outgoing data does get queued by the system, and is not transferred until the user switches back to that watch). 未连接的监视应用程序可以继续使用所有传输方法, 包括交互式消息传递 (尽管传出的数据确实由系统排队,并且在用户切换回该监视之前不会传输)。

I've verified that data is queued, using two different approaches: 我已经使用两种不同的方法验证了数据是否已排队:

  • by using transferUserInfo dictionary from a watch, letting the run loop execute, repeating that process a few times, then examining the outstandingUserInfoTransfers array. 通过使用watch中的transferUserInfo字典,让run循环执行,重复该过程几次,然后检查outstandingUserInfoTransfers数组。
  • by using a sendMessage reply handler which only runs after the user switches back to that watch, and a response is received. 通过使用sendMessage回复处理程序,该处理程序仅在用户切换回该监视后运行,并且收到响应。

Once switching back, all queued transfers are immediately sent to its phone, and any interactive responses are then received by the watch. 一旦切换回来,所有排队的传输将立即发送到其电话,然后手表会收到任何交互式响应。

While an unconnected watch is able to queue data to its paired iPhone (since its session is still active), the phone can only communicate with its connected watch, since the phone no longer has an active session to any unconnected watch. 虽然未连接的手表能够将数据排队到其配对的iPhone(因为其会话仍处于活动状态),但手机只能与其连接的手表通信,因为手机不再具有与任何未连接手表的活动会话。

New sample code: 新示例代码:

You can try out the new QuickSwitch sample code . 您可以试用新的QuickSwitch示例代码 It uses updateApplicationContext to pass a designator and color from any of the watches to the phone. 它使用updateApplicationContextupdateApplicationContext和颜色从任何手表传递到手机。

You can change the designator and color for an unused watch, use the Xcode Devices pane to switch to that watch, then notice that the iOS app immediately shows that watch's new designator and color (which was queued while the watch was unused). 您可以更改标志和颜色未使用的手表,使用的Xcode的设备窗格中切换到该表,然后注意到iOS应用会立即显示该腕表的新标志和颜色( 手表是未使用其排队)。

Possible reachable documentation inconsistency: 可能reachable文档不一致:

In your WatchKit extension, the value of this property is YES when a matching session is active on the user's iPhone and the device is within range so that communication may occur. 在WatchKit扩展中,当用户的iPhone上的匹配会话处于活动状态并且设备在范围内时,此属性的值为YES,以便可以进行通信。

Since I don't have a second watch, I couldn't test whether an unused watch's reachability ever changes to false, once its phone moves out of range. 由于我没有第二块手表,一旦手机超出范围,我无法测试未使用的手表的可达性是否会变为假。

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

相关问题 从配对的Apple Watch启动iPhone应用程序 - Launching iPhone app from paired apple watch 检查 iPhone 是否与 Apple Watch 配对? - Check if iPhone is paired with apple watch? 我可以在没有配备XCode的Apple Watch的情况下在我的设备上运行我的应用程序,即使它具有Apple Watch目标? - Can I run my app on my device without a paired Apple Watch from XCode, even if it has an Apple Watch target? 使用watchOS 2,我可以在iPhone和Apple Watch之间发送UIImage的速度有多快? - How fast can I send a UIImage between an iPhone and Apple Watch, with watchOS 2? 如何获得iPhone和配对的Apple Watch之间的当前距离 - how to get current distance between iPhone and paired Apple Watch 有没有办法检测 Apple Watch 是否与 iPhone 配对? - Is there a way to detect if an Apple Watch is paired with an iPhone? 检查 Apple Watch 当前是否与 iPhone 配对 - Check if Apple watch is currently paired with iPhone 在watchOS4中从Apple Watch应用程序到iPhone应用程序共享实时数据的最佳方法是什么? - Whats the best way to share real time data from an apple watch app to iphone app in watchOS4? Apple Watch应用可检测苹果手表是否与手机配对 - Apple Watch app detect if a apple watch is paired with the phone 苹果手表应用程序如何与其配套的iPhone应用程序共享cookie会话? - How apple watch app share cookie session with its companion iPhone app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM