In my app I'm using card.io to scan credit cards. It works fine in iOS 9. In iOS 10, the app is crashing and I cannot find the crash log in the xcode 8 beta 2 console as it throws a lot of garbage messages.
And then I checked in privacy->settings to see if camera is disabled for my app, but my app is not listed in that section.Seems that iOS 10 is not grnating permission for my app to use the camera.
I use the following code to request the permission:
-(BOOL)checkCameraPermissions{
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
if(authStatus == AVAuthorizationStatusAuthorized)
{
// start card-io
return YES;
}
else if(authStatus == AVAuthorizationStatusNotDetermined)
{
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted)
{
if(granted)
{
//Start card-io
[self testIsNewCard];
}
}];
}
else if (authStatus == AVAuthorizationStatusRestricted)
{
//Alert
// Alert camera denied
UIAlertController *aCon=[UIAlertController alertControllerWithTitle:@"Camera denied" message:@"Camera cannot be used" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *ok =[UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[aCon dismissViewControllerAnimated:YES completion:nil];
}];
[aCon addAction:ok];
[self presentViewController:aCon animated:YES completion:nil];
return NO;
}
return NO;
}
When I run this code, the authStatus is returned as AVAuthorizationStatusNotDetermined
and the app crashed right after it enter into the block requestAccessForMediaType:AVMediaTypeVideo
There is so much of garbage logs displaying in console and I have no clue to find the crash message.
Edit: I found an option to disable the all the unnecessary logs in xcode 8. Answer posted here. But still xcode didn't showed any crash log even after disabling the backtrace debugging.
My xcode8 just shows this message and the app just quits:
App[1124:226447] [access] <private>
I also tried resetting the location and privacy , but still the app crashes when trying to request the media access.
Any ideas why this is happening ?
I added the "Privacy - Camera Usage Description"
key to my info.plist file and it works now.
In iOS 10
you must declare access to any user private data types. You do this by adding a usage key to your app’s Info.plist
. For more information please find the below screenshot for the same.
You need to add the Privacy - Camera 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 NSCameraUsageDescription key.
Just copy and paste below string in info.plist.
<key>NSCameraUsageDescription</key>
<string>Take the photo</string>
Please find the below GIF for more information.
For more information please review the link.
iOS 10
has continued the privacy policy and has implemented new privacy rules. And we should remember to implement them in our next projects.
For your issue you need to add following line into info.plist
<!-- 📷 Camera -->
<key>NSCameraUsageDescription</key>
<string><Your description goes here></string>
Below are the rest of the privacy rules :
<!-- 🖼 Photo Library -->
<key>NSPhotoLibraryUsageDescription</key>
<string><Your description goes here></string>
<!-- 📷 Camera -->
<key>NSCameraUsageDescription</key>
<string><Your description goes here></string>
<!-- 🎤 Microphone -->
<key>NSMicrophoneUsageDescription</key>
<string><Your description goes here></string>
<!-- 📍 Location -->
<key>NSLocationUsageDescription</key>
<string><Your description goes here></string>
<!-- 📍 Location When In Use -->
<key>NSLocationWhenInUseUsageDescription</key>
<string><Your description goes here></string>
<!-- 📍 Location Always -->
<key>NSLocationAlwaysUsageDescription</key>
<string><Your description goes here></string>
<!-- 📆 Calendars -->
<key>NSCalendarsUsageDescription</key>
<string><Your description goes here></string>
<!-- ⏰ Reminders -->
<key>NSRemindersUsageDescription</key>
<string><Your description goes here></string>
<!-- 🏊 Motion -->
<key>NSMotionUsageDescription</key>
<string><Your description goes here></string>
<!-- 💊 Health Update -->
<key>NSHealthUpdateUsageDescription</key>
<string><Your description goes here></string>
<!-- 💊 Health Share -->
<key>NSHealthShareUsageDescription</key>
<string><Your description goes here></string>
<!-- ᛒ🔵 Bluetooth Peripheral -->
<key>NSBluetoothPeripheralUsageDescription</key>
<string><Your description goes here></string>
<!-- 🎵 Media Library -->
<key>NSAppleMusicUsageDescription</key>
<string><Your description goes here></string>
Hope this helps. :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With