电子应用不要求在Macos Monterey上获得相机和麦克风许可

发布于 2025-01-24 07:00:43 字数 335 浏览 6 评论 0 原文

我已经建立了堆栈电子和ReactJ的应用。我正在尝试从应用程序访问相机和麦克风。但是,该应用在要求时不要求许可,也不会在系统首选项中显示-GT;相机和麦克风下的安全性和隐私。 以下是我使用的版本:

"electron": "^15.3.0",
"electron-builder": "^22.14.5",
"electron-devtools-installer": "^3.2.0",
"electron-notarize": "^1.1.1",
"electron-rebuild": "^3.2.3", 
"react": "^17.0.2"

让我知道我缺少什么或需要更改。提前致谢。

I have built an application of stack electron and reactjs. I am trying to access the camera and microphone from the application. But the app does not ask for permission when requested and also it does not show in the System Preferences -> Security and Privacy under camera and microphone.
Below are the versions I am using:

"electron": "^15.3.0",
"electron-builder": "^22.14.5",
"electron-devtools-installer": "^3.2.0",
"electron-notarize": "^1.1.1",
"electron-rebuild": "^3.2.3", 
"react": "^17.0.2"

Let me know what I am missing or needs to be changed. Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

疾风者 2025-01-31 07:00:43

我也遇到了这个问题,它在Macos Catalina效果很好,但在蒙特雷,有时效果很好。

我在电子官方文档中阅读了此信息后解决了:

“如果您打算使用Electron的API访问应用程序中的麦克风或相机,则还需要添加以下权利”

<key>com.apple.security.device.audio-input</key>
<true/>
<key>com.apple.security.device.camera</key>
<true/>

来添加授权,因为您正在使用> code>电子构建器有一个可以在 package.json 中使用的配置,将其添加到“ mac” 下,您需要添加此:

"extendInfo": {
        "NSMicrophoneUsageDescription": "Please give us access to your microphone",
        "NSCameraUsageDescription": "Please give us access to your camera",
        "com.apple.security.device.audio-input": true,
        "com.apple.security.device.camera": true
      },

然后您需要添加以下几行要求媒体权限:


const { systemPreferences } = require('electron')

const microphone = systemPreferences.askForMediaAccess('microphone');
const camera = systemPreferences.askForMediaAccess('camera');

I also had this problem it worked fine in macOS Catalina but in Monterey sometimes it didn't.

I solved after reading this in the electron official documentation:

"If you plan to access the microphone or camera within your app using Electron's APIs, you'll also need to add the following entitlements"

<key>com.apple.security.device.audio-input</key>
<true/>
<key>com.apple.security.device.camera</key>
<true/>

To add the entitlements since you are using electron-builder there's a config that you can use in package.json to add it under "mac" you add this:

"extendInfo": {
        "NSMicrophoneUsageDescription": "Please give us access to your microphone",
        "NSCameraUsageDescription": "Please give us access to your camera",
        "com.apple.security.device.audio-input": true,
        "com.apple.security.device.camera": true
      },

And then you need to add the following lines to ask for media permissions:


const { systemPreferences } = require('electron')

const microphone = systemPreferences.askForMediaAccess('microphone');
const camera = systemPreferences.askForMediaAccess('camera');

小矜持 2025-01-31 07:00:43

我想在

所以我找到了以下修复程序。在 mac 配置下,请添加以下属性为 false

"hardenedRuntime": false

I would like to add extra information with the answer of Caio Nakai
I'm having application crash issue with this fix also.

So I found the following fix. Under mac configuration please add the following property as false

"hardenedRuntime": false
八巷 2025-01-31 07:00:43

和平与善良!这对我有帮助:

systempreferences.askeformediaaccess('麦克风')
SystemPreferences.askformediaAccess('Camera'),

但仅使用

https:> https://www.electron.build/configuration/ mas

wittlements string | “未定义” - 签署应用程序的权利文件的路径。如果存在,将使用build/with.mas.mas.plist(这是推荐的设置方法)。有关示例,请参见OSX-Sign存储库中的此文件夹。 请注意,如果不像com.apple.security.cs.c.s.ally-jit设置正确的权利,则您的应用程序可能会崩溃电子文档以获取更多信息。

Peace and Kindness! This helped me:

systemPreferences.askForMediaAccess('microphone')
systemPreferences.askForMediaAccess('camera')

but only with it

https://www.electron.build/configuration/mas
https://github.com/electron/osx-sign/blob/main/entitlements/default.darwin.plist

entitlements String | “undefined” - The path to entitlements file for signing the app. build/entitlements.mas.plist will be used if exists (it is a recommended way to set). See this folder in osx-sign’s repository for examples. Be aware that your app may crash if the right entitlements are not set like com.apple.security.cs.allow-jit for example on arm64 builds with Electron 20+. See Signing and Notarizing macOS Builds from the Electron documentation for more information.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文