Electron-EE框架 在 MacOS 下 申請(qǐng)攝像頭及麥克風(fēng)權(quán)限踩坑指南

平臺(tái):mac
在項(xiàng)目打包后,訪問(wèn)某一頁(yè)面,調(diào)用了攝像頭麥克風(fēng),devTool disconnected from the page ...,然后就白屏,想到可能是權(quán)限的問(wèn)題
步驟如下:

  1. 在項(xiàng)目根目錄下創(chuàng)建一個(gè)entitlements.mac.plist文件,并寫(xiě)入下面的代碼;
<?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-jit</key>
    <true/>
    <key>com.apple.security.cs.allow-unsigned-executable-memory</key>
    <true/>
    <key>com.apple.security.cs.allow-dyld-environment-variables</key>
    <true/>
    <key>com.apple.security.device.audio-input</key>
    <true/>
    <key>com.apple.security.device.camera</key>
    <true/>
  </dict>
</plist>
  1. 在package.json中配置plist。
"entitlements": "entitlements.mac.plist",
"hardenedRuntime": true,
"extendInfo": {
    "NSMicrophoneUsageDescription": "請(qǐng)?jiān)试S本程序訪問(wèn)您的麥克風(fēng)",
    "NSCameraUsageDescription": "請(qǐng)?jiān)试S本程序訪問(wèn)您的攝像頭"
},

image.png

hardenedRuntime 這個(gè)屬性,在 electron-builder 的 21.1.3 版本已經(jīng)默認(rèn)為 true ,而在 21.1.2 ~ 20.41.0 版本里,這個(gè)屬性的默認(rèn)值是 false。再往后的版本里沒(méi)有這個(gè)屬性。

打包之后在某些電腦出現(xiàn)白屏devTool disconnected from the page ...,后來(lái)查詢得知

在 macOS 10.13 High Sierra 或更低版本上不需要用戶授權(quán),因此此方法總是返回 granted。 macOS 10.14 Mojave 或更高版本需要授權(quán)訪問(wèn) 麥克風(fēng) 和 攝像頭。 macOS 10.15 Catalina 或更高版本需要授權(quán)訪問(wèn) 屏幕。原文

高版本必須主動(dòng)去詢問(wèn)

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容