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
相关推荐
独隅7 小时前
RustRover MacOS 安装与实战效能全评测
macos·jetbrains·rustrover
陈工大模型1 天前
MacOS 跨平台压缩包处理:从编码痛点到工程化落地的完整方案
windows·macos·缓存·电脑·策略模式·c盘清理
fzlzjerry2 天前
我为什么自己写了一个原生 macOS 截图录屏工具:0 唤醒菜单栏架构与端侧 OCR 内存降 4 倍
macos
晚霞的不甘3 天前
Flutter/OpenHarmony 三方库适配实战:google_maps_flutter 地图
flutter·macos·华为·cocoa·harmonyos·1024程序员节
RobinDevNotes7 天前
24GB Mac 做数字人:声音放本地,画面租云端
人工智能·python·macos·开发工具
oil欧哟9 天前
Oil Studio 的产品思路与日常使用方式:在 Mac 上录口播演示,并接入 AI Agent 精剪与自动录屏
人工智能·macos
小毛球.11 天前
第 3 篇:IDEA 最新版下载与完整安装教程(Mac)
java·macos·intellij-idea·idea
CodeClimb12 天前
Mac 磁盘无法推出(DMG外接盘)排查处理教程
macos
Karl_fang13 天前
🥳 再也不用拿起手机抄验证码!我做了一个 Android → Mac 的「验证码接力」工具
前端·macos·ai编程
csdn_aspnet14 天前
macOS 10 、Docker 玩轉 MySQL
运维·mysql·macos·docker·容器·mac