iOS 10 error [access] <private> when using UIImagePickerController
Solution 1
You may need to put the NSPhotoLibraryUsageDescription in your plist. Like
<key>NSPhotoLibraryUsageDescription</key>
<string>$(PRODUCT_NAME) uses photos</string>
Check all the usage descriptions here.
Solution 2
In iOS10, Before you access privacy-sensitive data like Camera, Contacts, and so on, you must ask for the authorization, or your app will crash when you access them.Then Xcode will log like:
This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an
NSContactsUsageDescription
key with a string value explaining to the user how the app uses this data.
How to deal with this?
Open the file in your project named info.plist
, right click it, opening as Source Code
, paste this code below to it. Or you can open info.plist
as Property List
by default, click the add button, Xcode will give you the suggest completions while typing Privacy -
with the help of keyboard ⬆️ and ⬇️.
Remember to write your description why you ask for this authorization, between <string>
and </string>
, or your app will be rejected by apple:
<!-- 🖼 Photo Library -->
<key>NSPhotoLibraryUsageDescription</key>
<string>$(PRODUCT_NAME) photo use</string>
<!-- 📷 Camera -->
<key>NSCameraUsageDescription</key>
<string>$(PRODUCT_NAME) camera use</string>
<!-- 🖼 Write To Image Gallery>
<key>NSPhotoLibraryAddUsageDescription</key>
<string>$(PRODUCT_NAME) save phots in gallry</string>
<!-- 🎤 Microphone -->
<key>NSMicrophoneUsageDescription</key>
<string>$(PRODUCT_NAME) microphone use</string>
<!-- 📍 Location -->
<key>NSLocationUsageDescription</key>
<string>$(PRODUCT_NAME) location use</string>
<!-- 📍 Location When In Use -->
<key>NSLocationWhenInUseUsageDescription</key>
<string>$(PRODUCT_NAME) location use</string>
<!-- 📍 Location Always -->
<key>NSLocationAlwaysUsageDescription</key>
<string>$(PRODUCT_NAME) always uses location </string>
<!-- 📆 Calendars -->
<key>NSCalendarsUsageDescription</key>
<string>$(PRODUCT_NAME) calendar events</string>
<!-- ⏰ Reminders -->
<key>NSRemindersUsageDescription</key>
<string>$(PRODUCT_NAME) reminder use</string>
<!-- 📒 Contacts -->
<key>NSContactsUsageDescription</key>
<string>$(PRODUCT_NAME) contact use</string>
<!-- 🏊 Motion -->
<key>NSMotionUsageDescription</key>
<string>$(PRODUCT_NAME) motion use</string>
<!-- 💊 Health Update -->
<key>NSHealthUpdateUsageDescription</key>
<string>$(PRODUCT_NAME) heath update use</string>
<!-- 💊 Health Share -->
<key>NSHealthShareUsageDescription</key>
<string>$(PRODUCT_NAME) heath share use</string>
<!-- ᛒ🔵 Bluetooth Peripheral -->
<key>NSBluetoothPeripheralUsageDescription</key>
<string>$(PRODUCT_NAME) Bluetooth Peripheral use</string>
<!-- 🎵 Media Library -->
<key>NSAppleMusicUsageDescription</key>
<string>$(PRODUCT_NAME) media library use</string>
<!-- 📱 Siri -->
<key>NSSiriUsageDescription</key>
<string>$(PRODUCT_NAME) siri use</string>
<!-- 🏡 HomeKit -->
<key>NSHomeKitUsageDescription</key>
<string>$(PRODUCT_NAME) home kit use</string>
<!-- 📻 SpeechRecognition -->
<key>NSSpeechRecognitionUsageDescription</key>
<string>$(PRODUCT_NAME) speech use</string>
<!-- 📺 VideoSubscriber -->
<key>NSVideoSubscriberAccountUsageDescription</key>
<string>$(PRODUCT_NAME) tvProvider use</string>
If it does not works, try to ask for the the background authorization:
<key>UIBackgroundModes</key>
<array>
<!-- something you should use in background -->
<string>location</string>
</array>
Or go to target -> Capabilities -> Background Modes -> open the background Modes
:
then clean your Project, run it.
Go to here for more information: iOS10AdaptationTips .
Solution 3
in iOS 10 you need to add the key mentioned in below image if you are using camera or photo gallery in your app
Solution 4
You need the add the new privacy settings to you info.plist.
Don't forget to add the value describing why the app need to access the service.
Solution 5
In iOS 10, Apple has changed how you can access any user private data types.
You need to add the Privacy - Photo Library Usage Description key to your app’s Info.plist
and their usage information.
For more information please find the below GIF.
Or if you want to add via info.plist
then you need to add NSPhotoLibraryUsageDescription key.
Just copy and paste below string in info.plist
.
<key>NSPhotoLibraryUsageDescription</key>
<string>Take the photo</string>
Please find the below GIF for more information.
Related videos on Youtube
sudoExclaimationExclaimation
Updated on August 17, 2020Comments
-
sudoExclaimationExclaimation over 3 years
I am using XCode 8 and testing with iOS 10.2 Beta.
I have added the Photos, PhotosUI and MobileCoreServices frameworks to project.
Very simple code:
#import <Photos/Photos.h> #import <PhotosUI/PhotosUI.h> #import <MobileCoreServices/MobileCoreServices.h> @interface ViewController : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate, PHLivePhotoViewDelegate> @property (strong, nonatomic) IBOutlet UIImageView *imageview; @end
and implementation:
- (IBAction)grab:(UIButton *)sender{ UIImagePickerController *picker = [[UIImagePickerController alloc]init]; picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; picker.allowsEditing = NO; picker.delegate = self; // make sure we include Live Photos (otherwise we'll only get UIImages) NSArray *mediaTypes = @[(NSString *)kUTTypeImage, (NSString *)kUTTypeLivePhoto]; picker.mediaTypes = mediaTypes; // bring up the picker [self presentViewController:picker animated:YES completion:nil]; }
As soon as I tap the button, the app crashes with very useless error:
[access] <private>
That's it. Nothing else.
Using break statements, the app seems to crash at "presentViewController".
This is a brand new app and I don't have anything else in the UI other than the grab button.
Also, testing on iOS 9.3, this works fine. Am I missing something which might be changed in iOS 10?
-
Jordan Smith almost 8 yearsClean and then build. If no change, could easily be a bug in Xcode 8 or the iOS 10 beta that will get resolved by Apple in a future update. I often find this is the case - if it's the last beta, or the GM release and it still isn't working, then would be the time to worry about fixing it.
-
sudoExclaimationExclaimation almost 8 yearsyep, same issue even after clean and deleting the app :(
-
Jordan Smith almost 8 yearsI wouldn't stress about it. It's a Beta release. Chances are more likely that it's an issue with the beta. I'd suggest developing on Xcode 7 until much closer to release.
-
sudoExclaimationExclaimation almost 8 yearsok makes sense! thank you @Jordan
-
sudoExclaimationExclaimation almost 8 years@Jordan looks like there is a new requirement as of iOS 10. refer to solution: stackoverflow.com/a/38241350/1634905
-
-
sudoExclaimationExclaimation almost 8 yearssorry how did you find this release number?
-
rockdaswift almost 8 yearsIn the iOS downloads website, I just solved with the correct UsageDescription key.
-
sudoExclaimationExclaimation almost 8 yearsthank you, your answer resolved the issue right away! this is a new requirement since iOS 10. Welcome to Stack overflow btw!
-
lifjoy almost 8 yearsThanks so much! I got burned by NSAppleMusicUsageDescription (accessing iTunes music library).
-
Raheel Sadiq over 7 yearsI used this in my app, and is still rejected 4 times now, I added this key in my project and also in my pods projects. and there is nowhere I could find the use of photos in my workspace. Any ideas why it's happening? one more is the message must be a reason?
-
Raheel Sadiq over 7 yearsI used photos nowhere, and apple is rejecting my app, any idea?. I check all the pods projects as well
-
rockdaswift over 7 years@RaheelSadiq search in your workspace for photo, image or picker keywords. Maybe some pod is using some photo related class or library.
-
Raheel Sadiq over 7 years@iomer I already did that and searched other words as well like "asset" from ALAsset, I couldn't find any. I am using these libs: pod Alamofire, AlamofireImage, EGFloatingTextField, MXSegmentedPager. Any more hints or any idea that I can check, I would really appreciate it.
-
Raheel Sadiq over 7 years@iomer i fixed the issue, I did add the key in info.plist, but I couldn't see it under Project > Target > Info. So I added there as well, and Apple passed my Binary. It happened to me once before as well with Facebook ID. Don't know why it wasn't shown there.
-
Sajjon over 7 yearsOr use the text "Big brother sees you"! ;)
-
Mike over 7 yearsI do this and it works well for photos, but my app still crashes when I try to capture video. Any ideas?
-
Olivier de Jonge over 7 yearsThis should make your app not come through app store control.
-
James O'Brien over 7 yearsWhat if you don't use photos? I got a warning that I needed the key, then when I added it with no value, it rejected the binary
-
ChenYilong over 7 years@RaheelSadiq Remember to write your description why you ask for this authorization, between
<string>
and</string>
, or your app will be rejected by apple. -
Nasir Khan over 7 yearsand also <key>NSCameraUsageDescription</key><string>Take the photo</string>