iOS 10 - Changes in asking permissions of Camera, microphone and Photo Library causing application to crash
[UPDATED privacy keys list to iOS 13 - see below]
There is a list of all Cocoa Keys
that you can specify in your Info.plist
file:
https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html
(Xcode: Target -> Info -> Custom iOS Target Properties)
iOS already required permissions to access microphone, camera, and media library earlier (iOS 6, iOS 7), but since iOS 10 app will crash if you don't provide the description why you are asking for the permission (it can't be empty).
Privacy keys with example description:
Source
Alternatively, you can open Info.plist
as source code:
Source
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]
NFCReaderUsageDescription
NSAppleMusicUsageDescription
NSBluetoothAlwaysUsageDescription
NSBluetoothPeripheralUsageDescription
NSCalendarsUsageDescription
NSCameraUsageDescription
NSContactsUsageDescription
NSFaceIDUsageDescription
NSHealthShareUsageDescription
NSHealthUpdateUsageDescription
NSHomeKitUsageDescription
NSLocationAlwaysUsageDescription
NSLocationUsageDescription
NSLocationWhenInUseUsageDescription
NSMicrophoneUsageDescription
NSMotionUsageDescription
NSPhotoLibraryAddUsageDescription
NSPhotoLibraryUsageDescription
NSRemindersUsageDescription
NSSiriUsageDescription
NSSpeechRecognitionUsageDescription
NSVideoSubscriberAccountUsageDescription
Update 2019:
In the last months, two of my apps were rejected during 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).
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.
iOS app does not ask camera and microphone permissions on TestFlight?
To make sure your app has permission before capturing media, follow the steps below.
Configure Your App's Info.plist File
iOS requires that your app provide static messages to display to the user when the system asks for camera or microphone permission:
- If your app uses device cameras, include the Privacy - Camera Usage
Description key in your app’s Info.plist file. - If your app uses device photo library, include the Privacy - Photo
Library Usage Description key in your app’s Info.plist file
Verify and Request Authorization for Capture
You can add below code in AppDelegate main file OR while click on capture media to request access authorization.
import AVFoundation
AVCaptureDevice.requestAccess(for: .video) { granted in
if granted {
// Setup your code.
}
}
Apple Ref Link https://developer.apple.com/documentation/avfoundation/cameras_and_media_capture/requesting_authorization_for_media_capture_on_ios
Using device CAMERA ON IOS 10 causes the application to be terminated
I Solved This issue:-
Go to info.plist - Your Xcode bundle
Click the "+" and go down the resulting list until you see "Privacy - Camera Usage Description". Add this item to by clicking it inside that list.
Format
..-Info.Plist
Key :- Privacy - Camera Usage Description
Type :- string
Value :- empty - Don't enter anything
Just clean xcode project and run it ... it's worked for me.
Apple store demands audio permissions in {mediaType: 'photo'}
The microphone permissions probably would be demanded because from mediaType 'Photo' the user could access to the video recorder witch could record audio too ( a video is a mix of photo and audio ).
Request Permission for Camera and Library in iOS 10 - Info.plist
You have to add the below permission in Info.plist. More Referance
Camera :
Key : Privacy - Camera Usage Description
Value : $(PRODUCT_NAME) camera use
Photo :
Key : Privacy - Photo Library Usage Description
Value : $(PRODUCT_NAME) photo use
iOS10 UIImageWriteToSavedPhotosAlbum TCC__CRASHING_DUE_TO_PRIVACY_VIOLATION
You can save any UIImage to the photo album but first you must ask the user for permission to do as this as it is indeed a privacy issue. If they don't give you access then you can't save the image at all.
The most sensible approach is to add the required privacy key to the info.plist.
This is the info.plist xml definition although it's easier to add the keys in the property list:
<key>NSPhotoLibraryAddUsageDescription</key>
<string>Message requesting the ability to add to the photo library</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>Message requestion the ability to access the photo library</string>
If you add these then when you first try to access or add to the photo library a popup will display with your message allowing the user to decide if they want your app to have access.
One good reason to put it in the info.plist file is that all the requests for access are then in a single easily visible place instead of somewhere random in your project.
EDIT
Here is how to save the image in documents which does not raise and privacy issues:
NSData *imageData = UIImagePNGRepresentation(image);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath = [paths objectAtIndex:0]; //Get the docs directory
NSString *filePath = [documentsPath stringByAppendingPathComponent:@"image.png"]; //Add the file name
[imageData writeToFile:filePath atomically:YES]; //Write the file
If you want a jpg instead of a png use this instead:
NSData *imageData = UIImageJPEGRepresentation(image, 0.9); // Use whatever compression ratio you want instead of 0.9
Related Topics
Why Is the Tab Bar Disappearing
Swift - Json Error: the Data Couldn'T Be Read Because It Isn'T in the Correct Format
Redirect to Application If Installed, Otherwise to App Store
How to Add Spacing Between Uitableviewcell
Update Badge With Push Notification While App in Background
Force View Controller to Reload to Refresh Uiappearance Changes
React-Native, How to Get File-Asset Image Absolute Path
Ios: How to Make a Shadow for Uiview on 4 Side (Top,Right,Bottom and Left)
Download Array of Images as Byte Array and Convert to Images
Firebase Custom Event Parameters Not Visible in Console
How to Display 3 Cells Per Row in Uicollectionview
Swift 2.0 - Binary Operator "|" Cannot Be Applied to Two Uiusernotificationtype Operands
Change Paid App to Free But Know If User Previously Purchased It
An Error Was Encountered While Running (Domain = Launchserviceserror, Code = 0)
Dateformatter'S Returns Nil For Specific Date Strings Without Time in Swift
Is [Uiscreen Mainscreen].Bounds.Size Becoming Orientation-Dependent in Ios8