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
相关推荐
大熊猫侯佩1 天前
升级到 macOS26.5 后看视频会自动息屏的解决
macos·操作系统
磊 子2 天前
C++ IO 流
macos·objective-c·cocoa
real_haha2 天前
我做了一个仅有 1.3 MB 的 macOS 原生 AI 助手:AskNow
人工智能·macos
June bug2 天前
(Mac)macOS x86_64上onnxruntime==1.24.4 安装失败
macos
ACP广源盛139246256732 天前
iOS 27 开放 AI 生态@ACP#小型化扩展黄金风口,IX8008全面超越 ASM2806,铸就嵌入式 AI 扩展核心
人工智能·嵌入式硬件·macos·ios·计算机外设·objective-c·cocoa
海的辽阔2 天前
如何在MAC下安装EcomGpt模型
macos·大模型·ecomgpt
zandy10112 天前
hermes agent 安装教程 3.0:Win / Mac / Linux 全平台指南
linux·运维·macos
花开·莫之弃2 天前
Mac安装多版本jdk(jenv)
java·开发语言·macos
June bug2 天前
(Mac)torch==2.1.2 与 Python 3.12 不兼容+onnxruntime-silicon 不支持 Intel Mac
开发语言·python·macos
码农小北2 天前
MAC 配置鸿蒙(HarmonyOS) SDK 环境变量完整指南
macos·华为·harmonyos