最近我们在使用Go
的wails
框架配合Vue
实现一个网络工具类产品,可以兼容Windows,Linux,Mac 三端平台
在打包 Mac包的时候,遇到了难题,go的同事好不容易通过macapp.go
跑出了.app
程序,可以在开发的电脑上正常打开,但是没办法在别人电脑上安装。
花了两天时间,绕了一些弯路,找到了正确的方法,特此记录,并且分享出来。
一 证书
- 首先需要在apple开发者官网,证书中心(Certificates),注册两个证书
##### Developer ID Installer
This certificate is used to sign your app's Installer Package for distribution outside of the Mac App Store.
##### Developer ID Application
This certificate is used to code sign your app for distribution outside of the Mac App Store.
-
安装到电脑以后,在电脑
钥匙串
-> 登陆 -> 证书 大概可以看见Developer ID Installer: COMPANY LLC (123ABCDEF)
-
去AppleIDappleid.apple.com设置
App 专用密码
生成后的密码大概是这样的bwmj-bifq-uuvl-abcd
二 签名
- 把
.app
放在桌面的一个文件夹内 - 打开
终端
cd 进入文件夹内 - 使用 codesign 命令,通过
Developer ID Application
证书 签名.App
文件
sudo codesign -f --options=runtime -s "Developer ID Application: COMPANY LLC (123ABCDEF)" macapp.app --deep
- 使用 productbuild 命令对 .app 文件进行导出编译
sudo productbuild --component macapp.app /Applications --sign "Developer ID Installer: COMPANY LLC (123ABCDEF)" --product macapp.app/Contents/Info.plist productbuild.pkg
- 使用 productsign 对pkg安装包进行导出签名
sudo productsign --sign "Developer ID Installer: COMPANY LLC (123ABCDEF)" productbuild.pkg ./product.pkg
进行到这一步,就已经可以在别人的电脑上进行安装了,只是会提示异常风险
三 公证
- 提交公证
xcrun altool --notarize-app --primary-bundle-id "com.baidu.app" --username "123456@hotmail.com" --password "bwmj-bifq-uuvl-abcd" --asc-provider "123ABCDEF" --file product.pkg
xcrun altool --notarize-app // 公证命令
--primary-bundle-id "com.baidu.app" // 应用id
--username "123456@hotmail.com" // apple 账号
--password "bwmj-bifq-uuvl-abcd" // 上面设置的app 专用密码
--asc-provider "123ABCDEF" // 公司证书的team id
--file product.pkg // 需要公证的文件,可以是pkg/dmg/zip
- 公证 查询
如果提交正常,没有报错,就会提示
No Errors,RequestUUID = qw3a6e9-116c-409a-819f-f81f484edf12
等待大概10分钟,Apple会给你发一封邮件,告知你结果,同时也可以通过
xcrun altool --notarization-info qw3a6e9-116c-409a-819f-f81f484edf12 --username "123456@hotmail.com" --password "bwmj-bifq-uuvl-abcd"
查询结果,如果是Success,就代表成功了,否则,可以根据返回的log日志进行错误修改
- 公证验证
spctl -a -t install --context context:primary-signature -v product.pkg
资料来源