iOS 检查及获取相机、麦克风、相册、位置等权限

权限使用声明

我们知道,苹果对于应用访问用户的硬件设备时,有严格的访问权限。 iOS开发者在需要使用用户的设备前,需先检查一下各硬件的授权状态。 此外,我们还需要在应用程序的info.plist中配置访问硬件的使用声明 ( 增加需要授权key值并填写相应的权限使用声明)。 如果未添加使用描述,那么我们通常会收到如下崩溃信息:

“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.”

说明我们在使用麦克风权限时,未配置使用麦克风权限的使用声明导致的。

info.plist文件本质是一个xml文件, 默认的是可视化Property List显示方式。如下:
在这里插入图片描述
另一种查看方式是源代码方式显示。 在项目中找到info.plist 文件, 右键弹出的菜单中选择 Open As -> Source Code 即可

猜你喜欢

转载自blog.csdn.net/zhanglei5415/article/details/124587061