升級 iOS 10 以後目測坑仍是挺多的,記錄一下吧,看看到時候會不會成爲一個系列。app
直入正題吧this
今天用一個項目小小練下手,發現調用相機,崩了。試試看調用相冊,又特麼崩了。而後看到控制檯輸出瞭如下信息:
This app has crashed because it attempted to access privacy-sensitive data without a usage description.spa
The app's Info.plist must contain an NSPhotoLibraryUsageDescription key with a string value explaining to the user how the app uses this data.code
意思就是說,你須要在 info.plist 文件添加一個 NSPhotoLibraryUsageDescription
的 key,而後添加一個描述。blog
解決方案
1.在項目中找到info.plist
文件,右鍵點擊以 Source Code
形式打開
2.添加如下鍵值對,這裏以 PhotoLibrary 做爲例子ip
<key>NSPhotoLibraryUsageDescription</key> <string>此 App 須要您的贊成才能讀取媒體資料庫</string>
注意,key 是絕對不能寫錯的,ci
目測全部須要的權限描述都會在 iOS 10 beta裏面crash,不用怕,控制檯會有輸出的,自行添加就 OK,我另外附送幾個 key/value 給大家string
<key>NSCameraUsageDescription</key> <string>cameraDesciption</string> <key>NSContactsUsageDescription</key> <string>contactsDesciption</string> <key>NSMicrophoneUsageDescription</key> <string>microphoneDesciption</string>
固然我比較推薦的作法是直接info.plist
仍是用 Property List
的形式,而後點擊添加, 就是滑動到最後一個 item 會出現一個小加號
輸入 Privacy 能夠迅速定位到這一權限系列,找到你須要的權限,修改後面的 value 就能夠了it