macOS下打开麦克风崩溃

项目场景:

‌程序在 macOS 环境下尝试访问麦克风时发生崩溃。


问题描述

崩溃信息如下:

bash 复制代码
-------------------------------------
Translated Report (Full Report Below)
-------------------------------------
Process: test [2720]
Path: /Applications/test.app/Contents/MacOS/test
Identifier: hs.test Version: ???
Code Type: X86-64 (Native)
Parent Process: launchd [1]
User ID: 501
 
Date/Time: 2025-10-21 09:08:40.5221 +0800
OS Version: macOS 12.7.6 (21H1320)
Report Version: 12
Anonymous UUID: 4AEF0814-8866-A5DC-9EE9-7BC72539EBA0
 
Termination Reason: Namespace TCC, Code 0 This app has crashed because it attempted to access privacy-sensitive data without a usage description.
The app's Info.plist must contain an NSMicrophoneUsageDescription key with a string value explaining to the user how the app uses this data.

原因分析:

从最后一句描述可以看出,macOS(跟 iOS 类似)要求任何访问隐私相关硬件(如摄像头、麦克风、位置等)的应用,在 Info.plist 文件中声明用途描述。如果没有声明,系统会直接拒绝访问并触发崩溃。


解决方案:

在 test.app/Contents/Info.plist 中添加以下键值:

bash 复制代码
<key>NSMicrophoneUsageDescription</key>
<string>此应用需要访问麦克风以进行音频采集或语音对讲。</string>

如果程序还需要使用摄像头(比如视频通话或监控),要同时加上:

bash 复制代码
<key>NSCameraUsageDescription</key>
<string>此应用需要访问摄像头以进行视频预览或录像。</string>

如果是已打包的 .app,可以通过命令行修改:

bash 复制代码
/usr/libexec/PlistBuddy -c "Add :NSMicrophoneUsageDescription string '此应用需要访问麦克风以进行音频采集或语音对讲。'" /Applications/test.app/Contents/Info.plist
相关推荐
汤姆yu14 小时前
Mac 上 2026 版 OpenClaw 安装与配置全流程
macos·openclasw安装
MonkeyKing_sunyuhua15 小时前
K8S执行MAC打出的本地镜像错误:exec /usr/local/bin/uvicorn: exec format error
macos·容器·kubernetes
小路恢弘20 小时前
xcode替换LLVM插件
ide·macos·xcode
ChengQianO21 小时前
从 0 开始:Mac 下 UTM 虚拟机安装 ROS Noetic(Ubuntu 20.04)
linux·ubuntu·macos
草帽lufei1 天前
macOS中的Cursor等软件突然不能用了
macos·cursor
Rabbit_QL1 天前
【Warp+Claude】任务完成自动通知(macOS + Warp 版)
macos·策略模式
X档案库1 天前
【ROS2】Mac M4 虚拟机 Ubuntu 24.04 安装 ROS2 Jazzy 新手教程
macos·机器人·ros
江城月下1 天前
从零开始:我在 Mac M1 上搭建离线 AI 知识库的实战记录
人工智能·macos
掘根2 天前
【即时通讯项目】环境搭建9——语言平台
ide·macos·xcode