App Playground项目中Info.plist位置及NSCameraUsageDescription配置
App Playground相机权限配置问题
我创建了一个包含如下代码的App Playground:
import SwiftUI import RealityKit struct ContentView: View { var body: some View { ARContainer() } } struct ARContainer: UIViewRepresentable { func makeUIView(context: Context) -> ARView { let arView = ARView(frame: .zero) arView.cameraMode = .ar // IMPORTANT return arView } func updateUIView(_ uiView: ARView, context: Context) { } }
运行到目标设备时触发崩溃,报错信息如下:
This app has crashed because it attempted to access privacy-sensitive
data without a usage description. The app's Info.plist must contain
an NSCameraUsageDescription key with a string value explaining to the
user how the app uses this data.
请问App Playground项目中Info.plist在哪里?如何在Info.plist中配置NSCameraUsageDescription?
找到Info.plist的位置
- 在Xcode左侧的项目导航栏中,展开你的Playground项目根节点
- 点击项目下的Info标签页,这里是Info.plist的可视化编辑界面;若要查看原始plist代码,可右键点击项目内的
Info.plist文件(默认已存在,若未显示可通过File > New > File...添加),选择Open As > Source Code
配置NSCameraUsageDescription
方式一:可视化编辑
- 在Info标签页的Custom iOS Target Properties区域,点击列表底部的
+按钮新增配置项 - 在Key列选择Privacy - Camera Usage Description(对应底层的
NSCameraUsageDescription键) - 在Value列输入权限说明文本,例如“需要访问相机以提供AR交互体验”
方式二:源码编辑
如果打开了Info.plist的源码视图,将以下代码插入到<dict>标签内部:
<key>NSCameraUsageDescription</key> <string>需要访问相机以提供AR交互体验</string>
内容的提问来源于stack exchange,提问作者kkk
相关产品推荐
相关产品推荐

