如何以编程方式区分两个不同的 Apple Watch?
How to differentiate two different Apple watch programmatically?
我打算开发 Apple Watch 应用程序。在开始编写代码之前,我几乎没有想过什么问题。
如何识别2个差异。手表。是否有一个我们可以使用的唯一标识符?
如果我为每个手表维护一个唯一标识符,当手表连接到iPhone,如何为各个手表选择正确的标识符。
如果我确实为 WATCH1 维护了一些特定的数据处理逻辑,并且如果我将它与新的 WATCH 配对,比如 watch 2,在某个时间点之后,如果我连接回 WATCH1,是否有最好的处理方式。
请帮忙弄清楚这些场景。
WCSession
提供了属性watchDirectoryURL
,你可以在其中存储特定于给定配对手表的数据,如果活动手表发生变化,这个目录也会改变。
来自 Apple 的文档:
Use this directory to store preferences, files, and other data that is relevant to the specific instance of your Watch app running on the currently paired Apple Watch. If more than one Apple Watch is paired with the same iPhone, the URL in this directory changes when the active Apple Watch changes.
您可以在此目录中存储您想要的任何信息,包括您的业务逻辑用来检测哪个手表当前处于活动状态的唯一标识符。
我打算开发 Apple Watch 应用程序。在开始编写代码之前,我几乎没有想过什么问题。
如何识别2个差异。手表。是否有一个我们可以使用的唯一标识符?
如果我为每个手表维护一个唯一标识符,当手表连接到iPhone,如何为各个手表选择正确的标识符。
如果我确实为 WATCH1 维护了一些特定的数据处理逻辑,并且如果我将它与新的 WATCH 配对,比如 watch 2,在某个时间点之后,如果我连接回 WATCH1,是否有最好的处理方式。
请帮忙弄清楚这些场景。
WCSession
提供了属性watchDirectoryURL
,你可以在其中存储特定于给定配对手表的数据,如果活动手表发生变化,这个目录也会改变。
来自 Apple 的文档:
Use this directory to store preferences, files, and other data that is relevant to the specific instance of your Watch app running on the currently paired Apple Watch. If more than one Apple Watch is paired with the same iPhone, the URL in this directory changes when the active Apple Watch changes.
您可以在此目录中存储您想要的任何信息,包括您的业务逻辑用来检测哪个手表当前处于活动状态的唯一标识符。