用途:在 App Store 之外分发 macOS 应用时,完成归档、Developer ID 导出与 Apple 公证流程。
前置条件:已安装 Xcode 并配置命令行工具;已完成认证(asc auth login 或 ASC_* 环境变量);本地钥匙串中存在 Developer ID Application 证书;Xcode 项目可构建 macOS 目标。
主要流程:
- 预检签名身份:security find-identity -v -p codesigning | grep "Developer ID Application"。若证书存在自定义信任覆盖导致 "Invalid trust settings" 或 "errSecInternalComponent",可用 security dump-trust-settings 检查,并用 security find-certificate 导出证书后 security remove-trusted-cert 移除覆盖,再用 codesign 验证证书链。
- 归档:xcodebuild archive -scheme "YourMacScheme" -configuration Release -archivePath /tmp/YourApp.xcarchive -destination "generic/platform=macOS"。
- 导出:创建 method 为 developer-id 的 ExportOptions plist,执行 xcodebuild -exportArchive -archivePath ... -exportPath ... -exportOptionsPlist ExportOptions.plist,生成带安全时间戳的签名 .app。
- 打包:ditto -c -k --keepParent 生成 ZIP。
- 提交公证:asc notarization submit --file ...,可加 --wait,或自定义 --poll-interval 30s --timeout 1h。
- 查询结果:asc notarization status --id "SUBMISSION_ID" --output table;失败时用 asc notarization log --id "SUBMISSION_ID" 获取日志,可 curl 日志 URL 查看详情;asc notarization list 可列出历史提交。
- 可选 stapling:xcrun stapler staple 应用或 DMG,使离线可用。
支持格式:.zip、.dmg、.pkg。PKG 需单独的 Developer ID Installer 证书,用 productsign 签名后再提交。
限制与注意:asc notarization 使用 Apple Notary API v2,而非 xcrun notarytool;认证复用其他 asc 命令的 API key;文件流式上传至 Apple S3,超过 5 GB 自动分片;大文件可用 ASC_UPLOAD_TIMEOUT 延长超时;Developer ID 证书无法通过 App Store Connect API 创建,需在 Apple 开发者账户页面创建。常见失败原因包括嵌套二进制未签名、缺少 hardened runtime、嵌入库无时间戳。使用前建议用 --help 核对参数。