tool

Mac上Electron打包后无法弹出请求摄像头权限问题

2020-11-26  本文已影响0人  _compass

公司对接了某个产品,让我打包Mac上应用,发现了在未公证之前的包是可以弹出是否能访问摄像头的;但是公证之后,即打包之后是不能的,无法弹出询问是否能访问摄像头。
后来发现,需要再entitlements.mac.plist里,添加允许访问camera和麦克风的权限:

```
<?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>
```

原因是因为:

In macOS 10.14 and later, the user must explicitly grant permission for each app to access cameras and microphones. Before your app can use the capture system for the first time, macOS shows an alert asking the user to grant your app access to the camera, as shown below. macOS remembers the user’s response to this alert, so subsequent uses of the capture system don’t cause it to appear again. The user can change permission settings for your app in System Preferences > Security & Privacy. The request for authorization looks different from the alert UI in iOS.

详情请见:
https://developer.apple.com/documentation/avfoundation/cameras_and_media_capture/requesting_authorization_for_media_capture_on_macos?language=objc

参见此文《Electron App 在 MacOS 下 申请摄像头及麦克风权限踩坑指南》
https://www.bugs.cc/p/electron-app-request-camera-and-microphone-permission-by-macos/

上一篇下一篇

猜你喜欢

热点阅读