1、權限以及相關設置
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
解決辦法(fix method):
在info.plist —Source Code中添加
UsageDescription相關的key, 描述字符串自己隨意填寫就可以,但是一定要填寫,不然會引發包無效的問題,導致上傳打包后構建版本一直不顯示。
<!-- 相冊 -->
<key>NSPhotoLibraryUsageDescription</key>
<string>App需要您的同意,才能訪問相冊</string>
<!-- 相機 -->
<key>NSCameraUsageDescription</key>
<string>App需要您的同意,才能訪問相機</string>
<!-- 麥克風 -->
<key>NSMicrophoneUsageDescription</key>
<string>App需要您的同意,才能訪問麥克風</string>
<!-- 位置 -->
<key>NSLocationUsageDescription</key>
<string>App需要您的同意,才能訪問位置</string>
<!-- 在使用期間訪問位置 -->
<key>NSLocationWhenInUseUsageDescription</key>
<string>App需要您的同意,才能在使用期間訪問位置</string>
<!-- 始終訪問位置 -->
<key>NSLocationAlwaysUsageDescription</key>
<string>App需要您的同意,才能始終訪問位置</string>
<!-- 日歷 -->
<key>NSCalendarsUsageDescription</key>
<string>App需要您的同意,才能訪問日歷</string>
<!-- 提醒事項 -->
<key>NSRemindersUsageDescription</key>
<string>App需要您的同意,才能訪問提醒事項</string>
<!-- 運動與健身 -->
<key>NSMotionUsageDescription</key>
<string>App需要您的同意,才能訪問運動與健身</string>
<!-- 健康更新 -->
<key>NSHealthUpdateUsageDescription</key>
<string>App需要您的同意,才能訪問健康更新 </string>
<!-- 健康分享 -->
<key>NSHealthShareUsageDescription</key>
<key>NSHealthShareUsageDescription</key>
<string>App需要您的同意,才能訪問健康分享</string>
<!-- 藍牙 -->
<key>NSBluetoothPeripheralUsageDescription</key>
<string>App需要您的同意,才能訪問藍牙</string>
<!-- 媒體資料庫 -->
<key>NSAppleMusicUsageDescription</key>
<string>App需要您的同意,才能訪問媒體資料庫</string>
如果不起作用,可以請求后台權限,類似於這樣:
<key>UIBackgroundModes</key> <array> <!-- 在這里寫上你在后台模式下要使用權限對應的key --> <string>location</string> ... </array>
或者在info.plist—Property List中添加
部分
麥克風權限:Privacy - Microphone Usage Description
通訊錄權限: Privacy - Contacts Usage Description
藍牙權限:Privacy - Bluetooth Peripheral Usage Description
語音轉文字權限:Privacy - Speech Recognition Usage Description
日歷權限:Privacy - Calendars Usage Description
定位權限:Privacy - Location When In Use Usage Description
定位權限: Privacy - Location Always Usage Description
定位的需要這么寫,防止上架被拒。

