# 公证你自己签名的 Mac App

> 附加你用 Developer ID 签名的 Mac App，让智能体把它发送到 Apple 的公证服务，在 Apple 拒绝时阅读日志，并把票据装订到文件上。

Source: https://air.build/cn/docs/build/notarize-a-mac-app-you-signed/

如果你自己分发 Mac App，例如在你的网站上提供下载，Apple 的公证服务会检查它并返回一张票据。智能体可以把你签名的 App 发送到公证服务，告诉你 Apple 的答复，并把票据装订到文件上，使票据随 App 一起分发。Apple 在 [Notarizing macOS software before distribution](https://developer.apple.com/documentation/security/notarizing-macos-software-before-distribution) 中说明了公证检查什么以及何时需要公证。

> [!NOTE]
> AirBuild 不会用 Developer ID 为 Mac App 签名，也不会创建 Developer ID 证书。在 AirBuild 中，`asc certificates create` 只创建 Wallet 卡券和 Apple Pay 证书，而 AirBuild 自己签名的构建版本用于 TestFlight 和 App Store。请先用你的 Developer ID 证书自行为 App 签名：参见 Apple 的 [Developer ID 证书](https://developer.apple.com/help/account/certificates/create-developer-id-certificates/)。
>
> AirBuild 没有用于公证的界面。你在项目的聊天中询问智能体，它会使用 `asc notarization`（参见[asc：签名、设备与用户](https://air.build/cn/docs/cli/asc-signing/#notarization)中的 notarization）。

> [!NOTE]
> Apple 的 [Developer ID 证书](https://developer.apple.com/help/account/certificates/create-developer-id-certificates/)页面说明，创建 Developer ID 证书需要你在 Apple 开发者团队中拥有账户持有人角色。

## 开始之前

- 团队的拥有者已关联 Apple 开发者账户并启用了一个团队。智能体会用该团队把 App 发送给 Apple。参见[关联你的 Apple 开发者账户](https://air.build/cn/docs/app-store/connect-apple-developer-account/)。
- 你的 App 已用你的 Developer ID 签名。上面的 Apple 页面列出了公证服务对 App 的其他要求。
- 文件为 `.zip`、`.dmg` 或 `.pkg`：这是该命令接受的三种类型。如果你附加的是 `.app`，AirBuild 会把它打包成 zip 后附加（例如 `MyApp.app.zip`）。如果 Apple 说签名无效，请按照 Apple 的 [Customizing the notarization workflow](https://developer.apple.com/documentation/security/customizing-the-notarization-workflow#Export-a-package-for-notarization) 所示自行压缩 App，或制作一个磁盘映像，然后附加它。

## 发送给 Apple

1. 在项目的聊天中把文件附加到一条消息里。参见[向智能体发送照片、文件和草图](https://air.build/cn/docs/projects/send-photos-and-files/)。

2. 询问，例如：

   ```text
   对附件中的 Mac App 进行公证，附加票据，然后把附加了票据的文件发给我。
   ```

3. 智能体用 `asc notarization submit --wait` 发送它。帮助说明，该命令会把文件上传到 Apple，并在加上 `--wait` 时等待 Apple 的结果。如果它先停止了等待，参见下面关于超时的问题。

4. 它会告诉你 Apple 的答复和该提交的 ID。状态为 `Accepted`、`In Progress`、`Invalid` 或 `Rejected` 之一。

发送文件不会更改它。当状态为 `Accepted` 时，智能体会继续[装订票据](https://air.build/cn/docs/build/notarize-a-mac-app-you-signed/#staple-the-ticket)。

## 如果 Apple 不接受

当状态为 `Invalid` 或 `Rejected` 时，命令会显示“Notarization failed”，并指向日志。询问：

```text
Apple 为什么没有通过？给我看公证日志里写了什么。
```

智能体用 `asc notarization log --fetch` 读取日志。帮助说明，日志包含“detailed information about the notarization result, including any issues found during the scan.”智能体可以在聊天中总结它，或者把它保存为文件（`--path`）并发给你。

App 是你签名的，所以需要你来修复：按日志的要求重新签名，附加新文件后再次询问。Apple 在 [Resolving common notarization issues](https://developer.apple.com/documentation/security/resolving-common-notarization-issues) 中列出了常见问题及其修复方法。

## 装订票据

装订会把 Apple 的票据附加到你的文件上。帮助说明，`asc notarization staple` 会附加票据并随即检查。它会更改文件本身，因此只有加上 `--confirm` 才会运行，智能体会先询问你。

- 可以装订的内容：已公证的 App 包（`.app`）、磁盘映像（`.dmg`）或已签名的安装器包（`.pkg`）。`.zip` 无法装订：帮助说明要装订其中的项目，然后重新压缩。智能体会为你完成这些操作。
- 运行位置：帮助说明装订只能在 Mac 上运行，而且 Apple 的装订工具可能需要联网。在本地团队中，智能体在你的 Mac 上工作，因此智能体会在那里装订。在云端团队中，本页无法确定智能体能否装订。如果它说装订工具“is supported on macOS only”，请在你的 Mac 上自行装订文件：Apple 的 [Customizing the notarization workflow](https://developer.apple.com/documentation/security/customizing-the-notarization-workflow) 说明了方法。参见[选择智能体的运行位置](https://air.build/cn/docs/get-started/where-agents-run/)。

智能体会在聊天中发回装订后的文件。按住它（在 Mac 上右键点按）并选择 **另存为…**。在 Mac 上，点按聊天中的 `.pkg` 或 `.dmg` 会在 Finder 中显示它，而不是打开它。参见[向智能体发送照片、文件和草图](https://air.build/cn/docs/projects/send-photos-and-files/#open-files-in-the-chat)。

之后要检查某个文件，请询问“附加的 App 有装订的票据吗？”智能体会用 `asc notarization validate` 检查，该命令不会更改文件，同样只能在 Mac 上运行。

## 之后查看提交

| 询问 | `asc` |
| --- | --- |
| “我的公证进展如何？” | `notarization status`，提供该提交的 ID。 |
| “列出我最近的五次公证。” | `notarization list`，加上 `--limit`。 |
| “给我看看最近一次公证的日志。” | `notarization log`，提供该提交的 ID。不加 `--fetch` 时，它会给出日志的链接，而不是日志内容。 |

## 常见问题

**智能体可以用 Developer ID 为我的 Mac App 签名吗？**

不可以。AirBuild 保存着你团队的分发证书和开发证书，并用它们为 TestFlight 和 App Store 构建版本签名，但不会用 Developer ID 签名。如果要求创建 Developer ID 证书，`asc certificates create` 会说该类型“is a signing certificate, which Airbuild manages”。请自行为 App 签名，然后附加它。

**智能体说不支持该文件类型。**

消息为“unsupported file type … (must be .zip, .dmg, or .pkg)”。请压缩 App，或把它放进磁盘映像或安装器包，然后附加。

**智能体说文件不能为空。**

收到的文件中没有任何内容。请在新消息中重新附加。

**智能体等待公证超时。**

消息以“timed out waiting for notarization”开头。文件已经上传，Apple 会继续检查。稍后询问“我的公证进展如何？”。

**智能体说 zip 归档无法装订。**

消息为“zip archives cannot be stapled or validated directly; staple the contained item and recreate the archive”。请让智能体装订 zip 中的 App，然后重新压缩。

**智能体说装订工具仅支持 macOS。**

装订只能在 Mac 上运行。请在你的 Mac 上自行装订文件（参见 Apple 的 [Customizing the notarization workflow](https://developer.apple.com/documentation/security/customizing-the-notarization-workflow)），或者使用本地团队，其智能体在你的 Mac 上工作。

**智能体说 xcrun 不可用。**

消息接着说：“install Xcode and ensure the active developer directory is configured”。在本地团队中，请在 Mac 上安装 Xcode，并在 **Xcode ▸ Settings ▸ Locations ▸ Command Line Tools** 中选择它。参见[选择智能体的运行位置](https://air.build/cn/docs/get-started/where-agents-run/#set-up-your-mac-for-a-local-team)。

**我的 Developer ID 证书还能继续使用吗？**

询问“我的 Developer ID 证书中有受 2027 年 2 月到期影响的吗？”智能体会用 `asc certificates developer-id-check` 检查。其帮助说明，来自原 Developer ID 证书颁发机构的证书将于 2027 年 2 月 1 日停止工作，用它们签名的 `.pkg` 安装器将无法再安装，应替换为来自 Developer ID 证书颁发机构 (G2) 的证书。每个证书的结果为 `affected`、`not-affected`、`likely-affected` 或 `unknown`。
