1.使用证书助理生成证书
2.创建证书到磁盘
3.创建苹果证书
选择 Developer ID Application
选择文件就选择刚才创建在磁盘的文件,然后下载到本地并双击安装到本机
developer.apple.com/account/res…
4.代码相关
(1)项目根目录创建notarize.js文件
const fs = require('fs')
const path = require('path')
var electron_notarize = require('electron-notarize')
require('dotenv').config()
module.exports = async function (params) {
if (process.platform !== 'darwin') {
return
}
let appBundleId = 'com.xiaochuan.desktop'
let appPath = path.join(
params.appOutDir,
`${params.packager.appInfo.productFilename}.app`
)
if (!fs.existsSync(appPath)) {
throw new Error(`Cannot find application at: ${appPath}`)
}
console.log(`Notarizing start`)
try {
await electron_notarize.notarize({
appBundleId: appBundleId,
appPath: appPath,
tool: 'notarytool',
teamId: '6938ST59MC',
appleId: 'xccy01@xiaochuanai.com',
appleIdPassword: 'qmhg-porp-fhgr-xwfu'
})
} catch (error) {
console.error(error)
throw error
}
console.log(`Done notarizing `)
}
(2)项目根目录创建entitlements.mac.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.files.user-selected.read-write</key>
<true/>
<key>com.apple.security.cs.allow-unsigned-executable-memory</key>
<true/>
<key>com.apple.security.device.audio-input</key>
<true/>
<key>com.apple.security.files.user-selected.read-only</key>
<true/>
<key>com.apple.security.cs.disable-library-validation</key>
<true/>
<key>com.apple.security.cs.allow-jit</key>
<true/>
</dict>
</plist>
(3)electron-builder配置
{
"appid":"com.ex.ket",
"asarUnpack": ["**/*.node"],
"afterSign": "notarize.js",
"mac": {
"target": [
{
"target": "dmg",
"arch": [
"x64",
"arm64"
]
}
],
"hardenedRuntime": true,
"gatekeeperAssess": false,
"entitlements": "./entitlements.mac.plist",
"entitlementsInherit": "./entitlements.mac.plist"
},
"dmg":{
"sign": true
},
}