在Electron 打包 Mac App Store 应用,苹果开发者证书的配置、上传 中,我们讲了如何打包给 App Store 分发的包的证书配置。
如果你不想把应用发到 App Store,那么你的应用也需要签名,进行公证。
如何安装没有公证的 App
没有公证的 App,第一次安装的话,可能会报错
遇到这种错误,网上会教一种解决办法
1. 打开“任何来源”
打开 「系统偏好设置->隐私与安全性」 选项卡,查看是否有 「任何来源」 的选项.
如果没有,则打开终端,输入sudo spctl --master-disable
命令执行。
2. 绕过公证
如果已经开启了“任何来源”, 但是还是打不开,那么可以通过以下步骤解决:
打开终端,输入:
<span class="token function">sudo</span> xattr -rd com.apple.quarantine /Applications/xxxxxx.app
xxxxxx.app
换成你的应用名称
然后重启 App。
这种方式虽然可以,但是如你已经有了苹果开发者证书,并且要分发 App 的话,进行公证还是有必要的,可以减少用户自己公证的操作,毕竟用户进行上面的操作,还有有门槛的。
Electron如何打包公证的包
在 Electron 打包 Mac App Store 应用,苹果开发者证书的配置、上传 中,我们创建了Mac App Distribution
, Mac Installer Distribution
证书,接着这篇文章,如果我们的应用不发布到 Mac App Store,我们需要的是Developer ID Installer
和 Developer ID Application
证书。
证书配置好,下载下来,安装到Keychain Access
打包配置文件如下:
const base = {
appId: 'com.xxxx.xxxx',
productName: 'Project Name',
buildVersion: "1",
afterSign: "./build/notarize.js",
files: ["**"],
extends: null,
productName: "GitHeat",
asar: true,
mac: {
target: [{
target: 'mas',
arch: ['universal']// ['x64', 'arm64']
},
{
target: 'dmg',
arch: ['x64', 'arm64'], // ['x64', 'arm64']
}],
hardenedRuntime: true,
gatekeeperAssess: false,
icon: path.join(__dirname, "../AppIcon/MyIcon.icns"),
category: 'public.app-category.utilities',
minimumSystemVersion: '12.0', // set minimum system version to 12.0 or higher
},
mas: {
icon: path.join(__dirname, "../AppIcon/MyIcon.icns"),
hardenedRuntime: false,
type: "distribution",
entitlements: 'build/parent.plist', // specify the path to the parent entitlements file
entitlementsInherit: 'build/child.plist', // specify the path to the child entitlements file
entitlementsLoginHelper: "build/entitlements.mas.loginhelper.plist",
provisioningProfile: 'build/embedded.provisionprofile'
},
};
module.exports = base;
大家仔细看,这个配置文件中多了一行 afterSign: "./build/notarize.js",
这个是electron-builder在打包的过程中,进行公证的脚本,我为了方便直接配置到这里了。
./build/notarize.js 的内容如下:
const {notarize} = require('electron-notarize');
exports.default = async function notarizing(context) {
const {electronPlatformName, appOutDir} = context;
if (electronPlatformName !== 'darwin') {
return;
}
const appName = context.packager.appInfo.productFilename;
return await notarize({
appPath: `${appOutDir}/${appName}.app`, appBundleId: 'com.xxx.xxxx', // appid
appleId: '[email protected]', // 苹果开发者 id
appleIdPassword: 'xxxxxxx', // 应用专用密码
ascProvider: 'teamID'
});
}
应用专用密码可以去https://appleid.apple.com/account/manage 申请。
这个密码只展示一次,如果丢了重新申请,不要泄露密码,尤其不要提交到 GitHub。
公证会把app
上传到 apple 服务器,会比较慢,如果失败了,会有错误链接,以及邮件。
如果你想通过命令行进行公证,也是可以的
xcrun altool --notarize-app --primary-bundle-id "com.xxx.xxx" --username "your developer appleid" --password "appleId-password" --asc-provider "ProviderShortname" -t osx --file xxx.dmg
验证签名
下载check-signature, 在苹果网站
https://developer.apple.com/download/all/?q=check-signatu
用命令./check-signature GitHeat.app
验证,可以看出返回YES
。
也可以用命令pkgutil --check-signature GitHeat.app
进行验证
返回如下:
用spctl -a -t exec -vv GitHeat.app
验证, 返回
移除签名的方式codesign --remove-signature xxxx.xx
签名命令:
codesign --sign <span class="token string">"Apple Distribution: xxxx (teamID)"</span> --timestamp --options runtime --entitlements ./build/parent.plist GitHeat.app
可以下载我的应用GitHeat – Git 活动日历热力图 验证命令。
发表回复