ios - 如何在iOS中识别不同连接的 watch

标签 ios watchkit apple-watch watchos-2 wcsession

来自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/

相关文章:

ios - 如何在 iPad 上禁用 4 指手势?

iphone - 在 UIGraphics 上下文中绘制矩形不起作用

iOS:Watch Kit 配对设备无法用于开发

ios - Apple Watch 应用中的黑屏输出

ios - 设置Tableview的backgroundView

ios - NSMutableString stringWithString 使应用程序崩溃

ios - 非动画滚动 WKInterfaceTable 到底部

ios - 添加 watch 应用程序时出现代码签名错误 - 嵌入式二进制文件未使用与父应用程序相同的证书进行签名

ios - 我可以让我的 WatchKit 应用程序在 Apple Watch 的后台运行吗?

ios - watchOS 2 : setting properties on initial Interface Controller