背景
昨天在測驗 Mac Electron App 打包,發現不簽名的應用能夠正常打開,簽了名的打開反而會崩潰,
尋因
首先我懷疑是不是自己代碼導致閃退,但是在一番查找后,發現還根本沒到執行我的代碼就閃退了,
然后就猜可能是我打包的引數缺了些東西,
我使用 electron-builder 打包的,當時配置的是:
"mac": { "category": "public.app-category.developer-tools", "target": "dmg", "icon": "res/logo.icns", "gatekeeperAssess": false}
我配置引數的原則是按需設定,加上這些能夠打包簽名我就不會再添加其他的,
原因
查看了 electron-builder 的檔案和網上資料后知道,蘋果要求簽名的應用的 runtime 必須是 hardened runtime,
這個時候應用的一些權限會受到限制,如果沒有相關權限設定就會因為權限不足而閃退,
PS:這里有一點我比較奇怪的,大概是前幾周,那時簽名的應用還能打開,
解決
1、添加一個plist檔案,設定權限,
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.cs.allow-unsigned-executable-memory</key> <true/> </dict></plist>
2、electron-builder配置增加
"mac": { "hardenedRuntime": true, "entitlements": "build/entitlements.mac.plist", "entitlementsInherit": "build/entitlements.mac.plist"}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/3768.html
標籤:其他
