1、找出本地的签名证书
#执行命令 列举出本地所有的签名证书
security find-identity -v
在输出中找到你的 Developer ID Application 证书,它应该类似:"Developer ID Application: Your Name (TeamID)"
2、给 archive出来的 .app的文件进行签名
先执行cd命令 进入到.app所在的文件夹进行操作
# 移除整个 .app 的签名
codesign --remove-signature "product_name.app"
# 使用上一步找到的证书名称替换 <Your_Developer_ID>
codesign --force --deep --sign "Developer ID Application: Your Name (TeamID)" \
--options runtime \
--timestamp \
"product_name.app"
--force:强制替换现有签名
--deep:递归签名,对 .app 包内的所有可执行文件、框架和插件进行签名(这是解决嵌套二进制文件问题的关键)
--options runtime:启用强化运行时 (Hardened Runtime),这是公证的强制要求
--timestamp:添加时间戳,确保签名在证书过期后仍有效
如果执行签名后出现product_name.app: unsealed contents present in the bundle root的错图提示,可能是在product_name.app的文件中包含了其他的文件夹刹删除即可。
product_name.app/
├── Contents/ # ✅ 这个目录应该存在
├── .DS_Store # ❌ 可能是隐藏文件
├── README.txt # ❌ 多余文件
└── Other files... # ❌ 不应该在根目录
3、将.app的文件做成dmg、pkg的包
pkg:适合安装软件时需要执行某些操作使用(安装过程中需要用户输入密码)
dmg:安装软件无需其他操作即可使用, 不需要额外的操作。
如何打包dmg、pkg 自行搜索
4、dmg签名 (这里对dmg进行举例)
先执行cd命令 进入到dmg所在的文件夹进行操作
codesign --sign "Developer ID Application: Your Name (TeamID)" \
--timestamp \
product_name.dmg
以上步骤完成了签名。重点是公证,很多人签名完后,漏了公证这一个,就会导致失败。公证的方法如下
5、 将 Apple 公证服务的凭据存储到 macOS 的钥匙串中(此步骤只从一次即可)
xcrun notarytool store-credentials "bieming" --apple-id "your apple id" --team-id " your team id" --password "app专用密码"
--password 后面是app专用密码,并非开发者账号的密码。需要你登陆https://account.apple.com 去生成
执行后以上命令后会提示
This process stores your credentials securely in the Keychain. You reference these credentials later using a profile name.
Validating your credentials...
Success. Credentials validated.
Credentials saved to Keychain.
To use them, specify `--keychain-profile "bieming"`
6、提交dmg文件
xcrun notarytool submit --force test.dmg --keychain-profile "bieming"
执行后提示
Conducting pre-submission checks for test.dmg and initiating connection to the Apple notary service...
Submission ID received
id: b9cc0d91-f788-434d-9faa-d495199aab91
Upload progress: 100.00% (2.62 MB of 2.62 MB)
Successfully uploaded file
id: b9cc0d91-f788-434d-9faa-d495199aab91
path: /Users/username/Desktop/打包证书/test.dmg
7、查询公证状态
xcrun notarytool info "b9cc0d91-f788-434d-9faa-d495199aab91" --keychain-profile "bieming"
执行后提示
#公证需要时间 有时候所依提示In Progress
Successfully received submission info
createdDate: 2026-01-20T08:59:01.291Z
id: b9cc0d91-f788-434d-9faa-d495199aab91
name: test.dmg
status: In Progress
# status: Accepted 就是好了
Successfully received submission info
createdDate: 2026-01-20T08:59:01.291Z
id: b9cc0d91-f788-434d-9faa-d495199aab91
name: test.dmg
status: Accepted
8、将公证信息注入 dmg文件中
xcrun stapler staple test.dmg
出现如下提示即成功 。可以讲dmg发给用户安装。
Processing: /Users/peanut/Desktop/打包证书/test.dmg
Processing: /Users/peanut/Desktop/打包证书/test.dmg
The staple and validate action worked!