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
相关推荐
aosky1 天前
手机远程畅玩OpenAI Codex
macos·智能手机·cocoa
A懿轩A1 天前
【2026 最新】Python 下载与安装:在 macOS 下使用 Homebrew 和 pyenv 完美管理多版本 Python
python·macos·mac
IKaros_α‌1 天前
mac上安装openclaw从入门到删除
macos
x-cmd1 天前
macOS 内存模型深度解析 | x free 设计哲学
linux·macos·内存·策略模式·free·x-cmd
itinymeng1 天前
在 macOS 上遇到 brew: command not found 错误,通常是因为 ‌Homebrew 未安装‌ 或 ‌PATH 环境变量未正确配置‌
macos
oscar9991 天前
Claude Code 的“计算机使用”功能:让命令行助手真正操控macOS桌面
macos·claude code·computer
老兵发新帖2 天前
软件开发国内常用镜像源配置及回退方法(MAC版)
macos·软件工程
qq_411262422 天前
ESP32-C5 软件配置MAC 地址
macos
鸠摩智首席音效师2 天前
如何在 MacOS 上安装 PostgreSQL ?
数据库·macos·postgresql
花千树-0102 天前
IndexTTS2 在 macOS 性能最佳设置(M1/M2/M3/M4 全适用)
人工智能·深度学习·macos·ai·语音识别·ai编程