来自watchOS >= 2.2 , iOS >= 9.3 iOS 设备能够通过 sessionDidDeactivate:
、sessionDidBecomeInactive:
连接多个 watch 设备。
但是,这些委托(delegate)调用中没有提供身份。
有没有系统方法可以识别不同的连接 watch 。
我必须手动操作它吗?
例如,检查新连接的 watch 是否有身份,如果没有则为其提供新的 ID。
watch 收到id后,还需要将其保存在某个地方。 NSUserDefaults
听起来在这种情况下是一个好地方。
最佳答案
来自WCSession
根据文档,Apple 建议将 watch 特定数据存储到 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 或类似的唯一标识符来区分 watch 。
关于ios - 如何在iOS中识别不同连接的 watch ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42237503/