watchOS 2.2应用程序如何确定其配对的iPhone是否已切换到另一个Apple Watch? [英] How can watchOS 2.2 app determine if its paired iPhone has switched to another Apple Watch?

查看:198
本文介绍了watchOS 2.2应用程序如何确定其配对的iPhone是否已切换到另一个Apple Watch?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在iOS 9.3/watchOS 2.2应用程序中支持与多只手表配对的新功能.它似乎运行良好,只是我无法弄清楚watchOS应用如何确定配对的iPhone是否已切换到另一台Apple Watch.

I'm trying to support the new feature for pairing with multiple watches in my iOS 9.3/watchOS 2.2 app. 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.

文档说,在整个切换生命周期中,从WatchKit扩展的角度来看,WCSession保持激活状态,并且根据我在Xcode中进行的测试,似乎该监视会话报告说iPhone也可以访问即使手机已切换到另一只手表.

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.

我目前没有多只手表可以检查实际设备上的行为是否相同.

推荐答案

您问题的具体答案:

手表不再连接的事实并不明显,因为可以使用所有传输方法,包括即时通讯.只是将转移推迟到用户切换回该手表之前.

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.

由于未连接的手表仍然可以启动与配对iPhone的传输,因此您可能必须实施某种握手或超时检测,并查看手机是否无法及时响应.

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.

我的发现:

似乎未连接的手表并不意味着知道用户已切换到其他手表.正如您所指出的,手表应用程序的会话仍处于活动状态,并且手表(模拟器)仍报告手机可以接通.

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

我已经使用两种不同的方法验证了数据是否已排队:

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

一旦切换回,所有排队的传输都会立即发送到手机,然后手表会收到所有互动响应.

Once switching back, all queued transfers are immediately sent to its phone, and any interactive responses are then received by the watch.

尽管未连接的手表能够将数据排队到其配对的iPhone(由于其会话仍处于活动状态),但手机只能与其已连接的手表通信,因为手机不再与任何未连接的手表保持活动会话观看.

新示例代码:

您可以尝试新的 QuickSwitch示例代码.它使用updateApplicationContext将指示符和颜色从任何手表传递到手机.

You can try out the new QuickSwitch sample code. It uses updateApplicationContext to pass a designator and color from any of the watches to the phone.

您可以更改未使用的手表的名称和颜色,使用"Xcode设备"窗格切换到该手表,然后注意iOS应用会立即显示该手表的新名称和颜色(在期间排队手表未使用.

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

可能的reachable文档不一致:

Possible reachable documentation inconsistency:

在您的WatchKit扩展程序中,当用户在iPhone上匹配会话处于活动状态且设备在允许范围内时,此属性的值为.

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.

由于我没有第二只手表,因此一旦手机移出范围,我无法测试未使用的手表的可达性是否会变为假.

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.

这篇关于watchOS 2.2应用程序如何确定其配对的iPhone是否已切换到另一个Apple Watch?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆