未签名的应用程序运行报错:
“Appname.dmg” can’t be opened because Apple cannot check it for malicious software.
This software needs to be updated. Contact the developer for more information.
或中文:
无法打开“Appname.app”,因为无法验证开发者。
macOS 无法验证此 App 不包含恶意软件。
electron-builder
打包工具,就具体介绍electron-builder
签名的方法, electron-builder
附带一个自定义解决方案,用于签署应用程序。 官方文档地址它的文档1、 打开钥匙串
2、 生成证书
3、 导出证书
1、登录Apple开发者后台,进入证书页面
2、点击
Certificates
添加证书,如果不在Apple store 发布的话选择:Developer ID Application
3、然后在你mac电脑登录打开Xcode
并登录你的开发者账号(很重要)
Electron-notarize
对 Electron
程序进行公证。package.json
// package.json { "build": { "afterSign": './mac/notarize.js', "mac": { "hardenedRuntime": true, // 使用强化的运行时构建您的应用程序 "gatekeeperAssess": false, // 禁用此健全性检查 "artifactName": '${productName}_${version}.${ext}', // 应用名称 "entitlements": './mac/entitlements.mas.plist', "entitlementsInherit": './mac/entitlements.mas.plist', }, } }```` "afterSign": './mac/notarize.js'`
"hardenedRuntime": true,
"gatekeeperAssess": false
"entitlements": './mac/entitlements.mas.plist'
notarize.js
// ./mac/notarize.js require('dotenv').config() 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({ appBundleId: 'com.ClientMacOS', // appid appPath: `${appOutDir}/${appName}.app`, // 应用的路径 xxx.app 结尾的 appleId: 'User@.com', // 苹果开发者 id appleIdPassword: 'PassWord', // 应用专用密码(可以是你的登录密码,也可以在苹果官网申请专用密码) ascProvider: 'XXXXXXXXX', // 证书提供者 }) }
appleId
appleIdPassword
ascProvider
entitlements.mas.plist
// ./mac/entitlements.mas.plist <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>com.apple.security.cs.allow-unsigned-executable-memory</key> <true/> </dict> </plist>
electron-builder
的命令,就可以在完成打包之后,继续执行签名,公正的工作,