如何在 iOS 中识别不同的连接手表

How to identify different connected watches in iOS

watchOS >= 2.2、iOS >= 9.3 iOS 设备可以通过 sessionDidDeactivate:sessionDidBecomeInactive:.[=15 连接多个手表设备=]

但是,这些委托调用中没有提供身份。

有什么系统方法可以识别不同的连接手表。

我必须手动操作吗? 例如,检查新连接的手表是否有标识,如果没有则给它新的标识。 收到 id 后,手表还需要将其保存在某个地方。 NSUserDefaults 在这种情况下听起来是个好地方。

根据 WCSession 文档,Apple 建议将 watch-specific 数据存储到 watchDirectoryURL 位置,并通过 WCSession

将此信息与连接的应用程序通信

Your iOS app can use the watchDirectoryURL property to store data that is specific to only one instance of your Watch app running on a particular Apple Watch. In most cases, the data you display in each instance of your Watch app is the same. However, you might use this directory to store configuration data, preferences, or other data files that your iOS app needs to interact properly with your Watch app. If you do, use the activation and deactivation process to update your iOS app.

您可以在此位置存储 UUID 或类似的唯一标识符以区分手表。