# watchOS

{% hint style="info" %}
对应的[官方页面地址](https://contributing.bitwarden.com/getting-started/mobile/net-maui-legacy/watchos/)
{% endhint %}

{% hint style="warning" %}
**Legacy**

在 .NET MAUI 中完成的**旧版** watchOS App 入门。
{% endhint %}

## 要求​ <a href="#requirements" id="requirements"></a>

按照 [iOS 设置](/getting-started/mobile/net-maui-legacy/ios.md)进行操作。

为了使一切正常工作，需要使用**设备**。在模拟器上，同步将无法正常工作（某些其他部分可能也无法正常工作）。此外，尽可能启用蓝牙功能，以简化设备间的同步和调试通信。

建议同时阅读 [watchOS 架构](/architecture/mobile-clients/net-maui-legacy/watchos.md)。

## macOS 设置​ <a href="#macos-setup" id="macos-setup"></a>

按照 iOS 的 macOS 设置，在 XCode 中打开项目时，它将自动设置配置文件，因此无需额外配置。

## 调试​ <a href="#debugging" id="debugging"></a>

可以从两个位置进行调试：

* 从 Visual Studio for Mac（iOS App）
* 从 XCode（watchOS App）

目前，无法同时调试两个 App（iOS 和 watchOS），因为从 Xamarin 中无法访问 watchOS App 的调试信息，并且从 XCode 中，iPhone 上安装了一个 iOS 存根 App 来对其进行调试。因此，在调试时需要选择要了解哪一部分的信息，从而确定是从 VS4M 还是从 XCode 进行调试。

{% hint style="warning" %}
从 XCode 进行调试时，Xamarin iOS App 将被替换为来自 XCode 的存根 App。因此 iOS App 上的任何配置都将丢失（例如服务器 URL）

从 VS4M 进行调试时，请在两次构建之间从 Apple Watch 上卸载之前的 watchOS App（如果有的话），以使其始终保持最新（如果不卸载以前的 watchOS App，有时它就不会更新）
{% endhint %}

### 构建 <a href="#building" id="building"></a>

鉴于 Xamarin iOS App 需要 Xcode 构建的输出，因此需要先从 XCode 构建 watchOS App，然后再从 VS4M 构建 iOS App，以便在设备上运行。

XCode 构建的输出存储在与 `iOS.csproj` 中配置的附近位置非常相似的位置：

```xml
<PropertyGroup>
    <WatchAppBuildPath Condition=" '$(Configuration)' == 'Debug' ">$(Home)/Library/Developer/Xcode/DerivedData/bitwarden-cbtqsueryycvflfzbsoteofskiyr/Build/Products</WatchAppBuildPath>
```

每一台 Mac 上的文件夹 `bitwarden-cbtqsueryycvflfzbsoteofskiyr` 很可能都不相同。因此，我们需要将 `iOS.csproj` 中的这一部分更改为 XCode 在本地自动创建的部分。

要知道路径确切是什么：在 XCode 中打开项目 -> 转到 Product -> 在 Finder 中 Show Build Folder。

*这一点需要改进，以便有一个固定的位置，或者有一个更简单的方法来自动获取它。*

{% hint style="warning" %}
需要特别注意两个 IDE 上的目标平台相同。因此，在设备上运行时，在 XCode 和 VS4M 上构建时都要以设备为目标，这样才能正确绑定 watchOS App。此外，还需要确保选择了「bitwarden WatchKit app」方案。
{% endhint %}

### 同步​ <a href="#synchronization" id="synchronization"></a>

由于上述原因，无法同时完全调试同步。

因此，我们只能调试一端 (iOS) 或另一端 (watchOS)。

如果需要「同时」检查两端的某些内容（如检查消息未发送/到达的原因），则需要使用控制台日志或将 Xamarin 代码的一部分调整到 Xcode 上的 iOS 存根 App，并从 XCode 调试同步。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dev.ppgg.in/getting-started/mobile/net-maui-legacy/watchos.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
