# asc：簽署、裝置與使用者

> 用於 Bundle ID 與功能、憑證、佈建描述檔、商家 ID 與票證類型 ID、App Clip ID、公證、裝置及 App Store Connect 使用者的 asc 指令。

Source: https://air.build/tw/docs/cli/asc-signing/

這些 [asc](https://air.build/tw/docs/cli/asc/) 指令群組用來管理 App 簽署所用的 Apple Developer 資源，以及 Apple 團隊中的成員與裝置。選擇 Apple 團隊（`--auth`）、輸出、分頁、`--confirm` 與結束代碼的運作方式，請參閱 [asc](https://air.build/tw/docs/cli/asc/) 頁面。

> [!NOTE]
> 使用 [runbuild](https://air.build/tw/docs/cli/runbuild/) `--sign` 建置時，不需要 `certificates` 或 `profiles`。`runbuild --sign` 會以 Apple 團隊的受管理簽署憑證，簽發、續期並嵌入每個 bundle 簽署所需的佈建描述檔，即使功能、App Group 或 iCloud 有所變更也一樣。若你刪除了它簽發的描述檔，下次簽署建置時會再次簽發。只有 AirBuild 建置以外的描述檔才需要使用 `profiles`。

在下方表格中，**主要旗標** 省略了幾乎每個指令都有的旗標：`--output` 與 `--pretty`（請參閱[輸出](https://air.build/tw/docs/cli/asc/#output)）、列表指令的 `--limit`、`--next` 與 `--paginate`（請參閱[分頁](https://air.build/tw/docs/cli/asc/#pagination)），以及用來選擇 Apple 回傳哪些屬性的 `--…-fields` 旗標。執行 `asc <family> <subcommand> --help` 可查看所有旗標、可用值與範例。若子指令本身還有子指令，表格中會改為列出這些子指令。

## bundle-ids

管理 Bundle ID 與功能。

| 子指令 | 作用 | 主要旗標 |
| --- | --- | --- |
| `list` | 列出 Bundle ID。 | `--capabilities-limit`, `--id`, `--identifier`, `--include`, `--name`, `--platform`, `--profiles-limit`, `--seed-id`, `--sort` |
| `view` | 依 ID 檢視 Bundle ID。 | `--id` |
| `app` | 檢視與 Bundle ID 連結的 App。 | 子指令：`view` |
| `profiles` | 列出與 Bundle ID 連結的描述檔。 | 子指令：`list` |
| `create` | 建立 Bundle ID。 | `--identifier`, `--name`, `--platform`, `--seed-id` |
| `update` | 更新 Bundle ID。 | `--id`, `--name` |
| `delete` | 刪除 Bundle ID。 | `--confirm`, `--id` |
| `capabilities` | 管理 Bundle ID 的功能。 | 子指令：`list`, `add`, `update`, `remove`, `reconcile` |

`bundle-ids capabilities --help` 會列出每個功能 ID，以及 Apple 公開 API 能否設定它。公開的功能以 `bundle-ids capabilities add --bundle BUNDLE_ID --capability ICLOUD`（以及 `remove`、`update`）設定。其他功能則透過團隊擁有者的 Apple 登入，以 `asc web bundle-ids capabilities enable|disable --bundle-id BUNDLE_RESOURCE_ID --capability ID --confirm` 設定（請參閱 [asc：網頁工作階段指令](https://air.build/tw/docs/cli/asc-web/)）。變更後，請讓 App 的 entitlements 與之相符並重新建置，以便重新簽發描述檔。

## certificates

管理簽署憑證。

| 子指令 | 作用 | 主要旗標 |
| --- | --- | --- |
| `list` | 列出簽署憑證。 | `--certificate-type`, `--display-name`, `--id`, `--include`, `--serial-number`, `--sort` |
| `view` | 依 ID 檢視簽署憑證。 | `--id`, `--include` |
| `developer-id-check` | 找出由將於 2027 年 2 月 1 日到期之中繼 CA 所簽發的 Developer ID 憑證。 | `--strict` |
| `csr` | 產生憑證簽署要求（CSR）。 | 子指令：`generate` |
| `export` | 將憑證與私密金鑰封裝為受保護的 PKCS#12 身分。 | `--certificate`, `--confirm`, `--csr`, `--force`, `--p12-out`, `--password-file`, `--private-key` |
| `create` | 建立 Wallet 票證或 Apple Pay 憑證。 | `--certificate-type`, `--common-name`, `--country`, `--csr`, `--csr-out`, `--email`, `--force`, `--generate-csr`, `--key-out`, `--key-size`, `--key-type`, `--merchant-id`, `--organization`, `--organizational-unit`, `--pass-type-id` |
| `update` | 更新簽署憑證。 | `--activated`, `--id` |
| `links` | 檢視憑證的關聯。 | 子指令：`pass-type-id` |

簽署憑證由 AirBuild 管理，`certificates create` 只會建立 Wallet 票證與 Apple Pay 憑證：`PASS_TYPE_ID`、`PASS_TYPE_ID_WITH_NFC`、`APPLE_PAY`、`APPLE_PAY_MERCHANT_IDENTITY`、`APPLE_PAY_PSP_IDENTITY`、`APPLE_PAY_RSA`。請傳入 `--csr FILE`，或使用 `--generate-csr` 搭配 `--key-out` 與 `--csr-out` 當場產生金鑰與要求。`certificates developer-id-check` 會找出由將於 2027 年 2 月 1 日到期之 Apple 憑證機構所簽發的 Developer ID 憑證。

## profiles

管理佈建描述檔。

| 子指令 | 作用 | 主要旗標 |
| --- | --- | --- |
| `list` | 列出佈建描述檔。 | `--id`, `--include`, `--include-stale`, `--limit-certificates`, `--limit-devices`, `--name`, `--profile-state`, `--profile-type`, `--sort`, `--stale-only` |
| `view` | 依 ID 檢視描述檔。 | `--id`, `--include` |
| `links` | 檢視描述檔的關聯。 | 子指令：`bundle-id`, `certificates`, `devices` |
| `create` | 建立佈建描述檔。 | `--bundle`, `--certificate`, `--device`, `--name`, `--profile-type` |
| `delete` | 刪除佈建描述檔。 | `--confirm`, `--id` |
| `download` | 下載佈建描述檔。 | `--id`, `--output-format` |
| `inspect` | 檢查本機的佈建描述檔。 | `--entitlements`, `--path` |

## merchant-ids

管理商家 ID 與其憑證。

| 子指令 | 作用 | 主要旗標 |
| --- | --- | --- |
| `list` | 列出商家 ID。 | `--certificates-limit`, `--identifier`, `--include`, `--name`, `--sort` |
| `view` | 依 ID 檢視商家 ID。 | `--certificates-limit`, `--include`, `--merchant-id` |
| `create` | 建立商家 ID。 | `--identifier`, `--name` |
| `update` | 更新商家 ID。 | `--clear-name`, `--merchant-id`, `--name` |
| `delete` | 刪除商家 ID。 | `--confirm`, `--merchant-id` |
| `certificates` | 管理商家 ID 憑證。 | 子指令：`list`, `view`, `create` |

## pass-type-ids

管理票證類型 ID。

| 子指令 | 作用 | 主要旗標 |
| --- | --- | --- |
| `list` | 列出票證類型 ID。 | `--id`, `--identifier`, `--include`, `--limit-certificates`, `--name`, `--sort` |
| `view` | 依 ID 檢視票證類型 ID。 | `--include`, `--limit-certificates`, `--pass-type-id` |
| `create` | 建立票證類型 ID。 | `--identifier`, `--name` |
| `update` | 更新票證類型 ID。 | `--name`, `--pass-type-id` |
| `delete` | 刪除票證類型 ID。 | `--confirm`, `--pass-type-id` |
| `certificates` | 列出票證類型 ID 憑證。 | 子指令：`list`, `view` |

## app-clip-ids

註冊 App Clip App ID（由 AirBuild 提供）。

| 子指令 | 作用 | 主要旗標 |
| --- | --- | --- |
| `list` | 列出團隊的 App Clip App ID。 |  |
| `create` | 在上層 App ID 之下註冊 App Clip App ID。 | `--identifier`, `--name`, `--parent-bundle-id` |

`bundle-ids create` 無法建立 App Clip App ID，但 `app-clip-ids create --parent-bundle-id com.example.app --identifier com.example.app.Clip --name "Example Clip"` 可以。上層 App ID 必須已存在，且 App Clip 識別碼必須以上層的識別碼開頭。若 App Clip 已存在，會直接回傳；若識別碼已被一般 App ID 使用，則會遭到拒絕。兩個指令都會輸出 `{items: [...]}`。

## notarization

管理 macOS 公證提交項目。

| 子指令 | 作用 | 主要旗標 |
| --- | --- | --- |
| `submit` | 提交軟體進行公證。 | `--file`, `--poll-interval`, `--timeout`, `--wait` |
| `staple` | 在本機附加並驗證 macOS 公證票證。 | `--confirm`, `--file` |
| `validate` | 在本機驗證已附加的 macOS 公證票證。 | `--file` |
| `status` | 取得公證提交項目的狀態。 | `--id` |
| `log` | 取得公證提交項目的開發者記錄 URL 或內容。 | `--fetch`, `--id`, `--overwrite`, `--path` |
| `list` | 列出先前的公證提交項目。 |  |

`notarization submit --file ./MyApp.dmg --wait` 會將 macOS App 傳送至 Apple 的公證服務並等待結果（`--timeout`、`--poll-interval`）。`status` 與 `log` 依 `--id` 讀取提交項目。`staple`（需要 `--confirm`）與 `validate` 會在本機檔案上附加並檢查票證。

## devices

管理 App Store Connect 中的裝置。

| 子指令 | 作用 | 主要旗標 |
| --- | --- | --- |
| `list` | 列出 App Store Connect 中的裝置。 | `--id`, `--name`, `--platform`, `--sort`, `--status`, `--udid` |
| `view` | 依 ID 檢視裝置。 | `--id` |
| `local-udid` | 取得本機 macOS 硬體 UDID。 |  |
| `register` | 註冊新裝置。 | `--confirm`, `--listen`, `--max-devices`, `--name`, `--output-file`, `--platform`, `--public-url`, `--stream`, `--ttl`, `--udid`, `--udid-from-system`, `--via-url` |
| `register-batch` | 從以 Tab 分隔的檔案註冊裝置。 | `--confirm`, `--continue-on-error`, `--dry-run`, `--file`, `--platform` |
| `update` | 更新裝置。 | `--id`, `--name`, `--status` |

`devices register --name NAME --udid UDID --platform IOS` 會新增一台裝置。`--via-url` 則改為透過註冊連結從使用者的裝置收集 UDID；加上 `--confirm` 即可註冊（否則會寫入 `--output-file`，供 `register-batch` 使用），`--public-url` 用來提供可連線的位址，`--max-devices` 與 `--ttl`（預設 `30m`）用來結束工作階段。`register-batch --file devices.txt --confirm` 會註冊以 Tab 分隔的清單。

## users

管理 App Store Connect 中的使用者與邀請。

| 子指令 | 作用 | 主要旗標 |
| --- | --- | --- |
| `list` | 列出 App Store Connect 中的使用者。 | `--email`, `--include`, `--role`, `--sort`, `--visible-app`, `--visible-apps-limit` |
| `view` | 依 ID 檢視使用者。 | `--id`, `--include` |
| `update` | 更新使用者。 | `--confirm`, `--id`, `--provisioning-allowed`, `--roles`, `--visible-app` |
| `delete` | 刪除使用者。 | `--confirm`, `--id` |
| `invite` | 邀請使用者。 | `--all-apps`, `--email`, `--first-name`, `--last-name`, `--provisioning-allowed`, `--roles`, `--visible-app` |
| `invites` | 管理使用者邀請。 | 子指令：`list`, `view`, `revoke`, `visible-apps` |
| `visible-apps` | 檢視使用者可見的 App。 | 子指令：`list`, `view` |

`users invite --email EMAIL --first-name NAME --last-name NAME --roles ADMIN` 會邀請某人加入 App Store Connect 團隊；`--all-apps` 或 `--visible-app` 設定對方能看到哪些 App。`users update` 可變更角色與 App；`users delete` 需要 `--confirm`。

## actors

依 ID 查詢操作者（使用者、API 金鑰）。

| 子指令 | 作用 | 主要旗標 |
| --- | --- | --- |
| `list` | 依 ID 列出操作者。 | `--id` |
| `view` | 依 ID 檢視操作者。 | `--id` |

## account

檢查帳號層級的健康狀態與存取訊號。

| 子指令 | 作用 | 主要旗標 |
| --- | --- | --- |
| `status` | 顯示帳號（account/workspace）的健康檢查結果。 | `--app` |

## 範例

註冊 Bundle ID 並開啟一項功能：

```bash
asc bundle-ids create --identifier "com.example.app" --name "Example" --platform IOS
asc bundle-ids capabilities add --bundle "BUNDLE_ID" --capability PUSH_NOTIFICATIONS
```

註冊測試人員的 iPhone：

```bash
asc devices register --name "Tester iPhone" --udid "UDID" --platform IOS
```

公證 Mac App 並附加票證：

```bash
asc notarization submit --file ./MyApp.dmg --wait
asc notarization staple --file ./MyApp.dmg --confirm
```
