您的位置:首页 > 移动开发 > IOS开发

ios10.0相册拍照闪退原因

2016-11-04 20:25 363 查看


iOS10系统下调用系统相册、相机功能,遇到闪退的情况,描述如下:

This app has crashed because it attempted to access privacy-sensitive data without a usage description.The app's Info.plist must
contain an NSPhotoLibraryUsageDescription key with a string value explaining to the user how the app uses this data.

修复方法:

在info.plist文件下添加

相机权限
<key>NSCameraUsageDescription</key>
<string>cameraDesciption</string>
 
相册权限
<key>NSPhotoLibraryUsageDescription</key>
<string>photoLibraryDesciption</string>

说法二

升级iOS10之后,在应用访问相册、相机、话筒、听筒的时候会发生崩溃。例如访问相机的时候xcode打印崩溃信息:

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

这是因为iOS对于隐私权限的配置更为严格。但是我看不出来哪里好了,用着还不方便。

解决办法:

更改info.plist文件,可以直接用文本打开,添加:

 
<key>NSCameraUsageDescription</key>
<string>cameraDesciption</string>
<key>NSContactsUsageDescription</key>
<string>contactsDesciption</string>
<key>NSMicrophoneUsageDescription</key>
<string>microphoneDesciption</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>photoLibraryDesciption</string>


也可以直接在xcode中更改:



这个string是我们开发者给起的一个表示,意思就是能随便写,但是要能表明其含义,它是给用户看的。第一次访问这些外设的时候会弹出提示框,上面就有显示这个string:



其它的权限key:

// 相机

NSCameraUsageDescription

// 相册

NSPhotoLibraryUsageDescription

// 麦克风:

NSMicrophoneUsageDescription

// 通信录

NSContactsUsageDescription

// 位置

NSLocationUsageDescription

// 日历

NSCalendarsUsageDescription 

// 蓝牙

NSBluetoothPeripheralUsageDescription

// 媒体资料库

NSAppleMusicUsageDescription

// 提醒事项

NSRemindersUsageDescription

// 在使用期间访问位置

NSLocationWhenInUseUsageDescription

// 始终访问位置

NSLocationAlwaysUsageDescription 

// 运动与健身

NSMotionUsageDescription

iOS10闪退 崩溃1:

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.

意思是说:你需要在info.plist文件 添加一个“NSContactsUsageDescription ”的Key,Value添加一个描述。

需要在应用的info.plist里加入(使用source code模式):
<key>NSCameraUsageDescription</key>
<string>cameraDesciption</string>
<key>NSContactsUsageDescription</key>
<string>contactsDesciption</string>
<key>NSMicrophoneUsageDescription</key>
<string>microphoneDesciption</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>photoLibraryDesciption</string>


原文出自:http://www.cnblogs.com/isItOk/p/5875203.html

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  iso10.0 相机 相册 奔溃