升級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文件,可以直接用文本打開,添加:
這個string是我們開發(fā)者給起的1個表示,意思就是能隨意寫,但是要能表明其含義,它是給用戶看的。第1次訪問這些外設的時候會彈出提示框,上面就有顯示這個string:
其它的權限key:
// 相機
NSCameraUsageDescription
// 相冊
NSPhotoLibraryUsageDescription
// 麥克風:
NSMicrophoneUsageDescription
// 通訊錄
NSContactsUsageDescription
// 位置
NSLocationUsageDescription
// 日歷
NSCalendarsUsageDescription
// 藍牙
NSBluetoothPeripheralUsageDescription
// 媒體資料庫
NSAppleMusicUsageDescription
// 提示事項
NSRemindersUsageDescription
// 在使用期間訪問位置
NSLocationWhenInUseUsageDescription
// 始終訪問位置
NSLocationAlwaysUsageDescription
// 運動與健身
NSMotionUsageDescription
更多iOS10的特性參考官方文檔:點擊打開鏈接