iOS 10 - 更改相机、麦克风和照片库的权限导致应用程序崩溃
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38498275/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
iOS 10 - Changes in asking permissions of Camera, microphone and Photo Library causing application to crash
提问by Syed Ali Salman
iOS 10, Now Requires User Permission to Access Media Library, Photos, Camera and other Hardware like these. The solution for this is to add their keys into info.plist
with a description for user that how we are using their data,
iOS 10,现在需要用户权限才能访问媒体库、照片、相机和其他类似的硬件。解决方案是将他们的密钥添加到info.plist
用户描述中,说明我们如何使用他们的数据,
I could only find a few keys
我只能找到几把钥匙
NSPhotoLibraryUsageDescription
NSMicrophoneUsageDescription
NSCameraUsageDescription
I want to know if there are more keys also for other hardware as in iOS 10
if you haven't provided info.plist
with proper keys description your application will crashif build using XCode - 8 beta.
我想知道是否还有其他硬件的更多密钥,iOS 10
如果您没有提供info.plist
正确的密钥描述,如果使用 XCode - 8 beta 构建,您的应用程序将崩溃。
回答by KlimczakM
[UPDATED privacy keys list to iOS 13 - see below]
[更新了 iOS 13 的隐私密钥列表 - 见下文]
There is a list of all Cocoa Keys
that you can specify in your Info.plist
file:
Cocoa Keys
您可以在Info.plist
文件中指定所有内容的列表:
(Xcode: Target -> Info -> Custom iOS Target Properties)
(Xcode:目标 -> 信息 -> 自定义 iOS 目标属性)
iOS already required permissions to access microphone, camera, and media library earlier (iOS 6, iOS 7), but since iOS 10 app will crashif you don't provide the description why you are asking for the permission (it can't be empty).
iOS 之前已经需要访问麦克风、摄像头和媒体库的权限(iOS 6、iOS 7),但由于 iOS 10 应用程序将崩溃,如果您不提供您请求权限的原因的描述(它不能是空的)。
Privacy keys with example description:
Alternatively, you can open Info.plist
as source code:
And add privacy keys like this:
并添加这样的隐私密钥:
<key>NSLocationAlwaysUsageDescription</key>
<string>${PRODUCT_NAME} always location use</string>
List of all privacy keys: [UPDATED to iOS 13]
所有私钥的列表:[更新至 iOS 13]
NFCReaderUsageDescription
NSAppleMusicUsageDescription
NSBluetoothAlwaysUsageDescription
NSBluetoothPeripheralUsageDescription
NSCalendarsUsageDescription
NSCameraUsageDescription
NSContactsUsageDescription
NSFaceIDUsageDescription
NSHealthShareUsageDescription
NSHealthUpdateUsageDescription
NSHomeKitUsageDescription
NSLocationAlwaysUsageDescription
NSLocationUsageDescription
NSLocationWhenInUseUsageDescription
NSMicrophoneUsageDescription
NSMotionUsageDescription
NSPhotoLibraryAddUsageDescription
NSPhotoLibraryUsageDescription
NSRemindersUsageDescription
NSSiriUsageDescription
NSSpeechRecognitionUsageDescription
NSVideoSubscriberAccountUsageDescription
Update 2019:
2019 年更新:
In the last months, two of my apps were rejectedduring the review because the camera usage description wasn't specifying what I do with taken photos.
在过去的几个月里,我的两个应用程序在期间被拒绝,因为相机使用说明没有具体说明我如何处理拍摄的照片。
I had to change the description from ${PRODUCT_NAME} need access to the camera to take a photo
to ${PRODUCT_NAME} need access to the camera to update your avatar
even though the app context was obvious (user tapped on the avatar).
我必须说明从改变${PRODUCT_NAME} need access to the camera to take a photo
到${PRODUCT_NAME} need access to the camera to update your avatar
,即使应用程序上下文是显而易见的(用户点击的头像)。
It seems that Apple is now paying even more attention to the privacy usage descriptions, and we should explain in details why we are asking for permission.
看来苹果现在更加注重隐私使用说明了,我们应该详细解释一下为什么要征求许可。
回答by Ilesh P
Please find below codes for ios 10 request permission sample for info.plist
.
You can modify for your custom message.
请在下面找到 ios 10 请求权限示例的代码info.plist
。
您可以修改自定义消息。
<key>NSCameraUsageDescription</key>
<string>${PRODUCT_NAME} Camera Usage</string>
<key>NSBluetoothPeripheralUsageDescription</key>
<string>${PRODUCT_NAME} BluetoothPeripheral</string>
<key>NSCalendarsUsageDescription</key>
<string>${PRODUCT_NAME} Calendar Usage</string>
<key>NSContactsUsageDescription</key>
<string>${PRODUCT_NAME} Contact fetch</string>
<key>NSHealthShareUsageDescription</key>
<string>${PRODUCT_NAME} Health Description</string>
<key>NSHealthUpdateUsageDescription</key>
<string>${PRODUCT_NAME} Health Updates</string>
<key>NSHomeKitUsageDescription</key>
<string>${PRODUCT_NAME} HomeKit Usage</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>${PRODUCT_NAME} Use location always</string>
<key>NSLocationUsageDescription</key>
<string>${PRODUCT_NAME} Location Updates</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>${PRODUCT_NAME} WhenInUse Location</string>
<key>NSAppleMusicUsageDescription</key>
<string>${PRODUCT_NAME} Music Usage</string>
<key>NSMicrophoneUsageDescription</key>
<string>${PRODUCT_NAME} Microphone Usage</string>
<key>NSMotionUsageDescription</key>
<string>${PRODUCT_NAME} Motion Usage</string>
<key>kTCCServiceMediaLibrary</key>
<string>${PRODUCT_NAME} MediaLibrary Usage</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>${PRODUCT_NAME} PhotoLibrary Usage</string>
<key>NSRemindersUsageDescription</key>
<string>${PRODUCT_NAME} Reminder Usage</string>
<key>NSSiriUsageDescription</key>
<string>${PRODUCT_NAME} Siri Usage</string>
<key>NSSpeechRecognitionUsageDescription</key>
<string>${PRODUCT_NAME} Speech Recognition Usage</string>
<key>NSVideoSubscriberAccountUsageDescription</key>
<string>${PRODUCT_NAME} Video Subscribe Usage</string>
iOS 11 and plus, If you want to add photo/image to your library then you must add this key
iOS 11 及更高版本,如果要将照片/图像添加到您的库中,则必须添加此密钥
<key>NSPhotoLibraryAddUsageDescription</key>
<string>${PRODUCT_NAME} library Usage</string>
回答by Kirit Modi
You have to add this permission in Info.plist for iOS 10.
您必须在 iOS 10 的 Info.plist 中添加此权限。
Photo :
照片 :
Key : Privacy - Photo Library Usage Description
Value : $(PRODUCT_NAME) photo use
Microphone :
麦克风 :
Key : Privacy - Microphone Usage Description
Value : $(PRODUCT_NAME) microphone use
Camera :
相机 :
Key : Privacy - Camera Usage Description
Value : $(PRODUCT_NAME) camera use