requestAccessForMediaType crashing in iOS 10
Asked Answered
I

3

20

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 ?

Imprescriptible answered 8/7, 2016 at 13:11 Comment(3)
did you find any solution for this?Buddleia
No, I'm still trying to figure it outImprescriptible
just exactly like you I do not get any crash logs!!Buddleia
T
27

I added the "Privacy - Camera Usage Description" key to my info.plist file and it works now.

Theurgy answered 13/7, 2016 at 16:12 Comment(2)
Strange that I added this previously and it didn't work last time but it worked now.Imprescriptible
Awesome answer! iOS 10 requires it.Inchon
L
11

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.

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.

GIF

For more information please review the link.

Lough answered 20/9, 2016 at 10:40 Comment(0)
R
8

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. :)

Retractor answered 22/9, 2016 at 7:6 Comment(2)
What if multiple Use of camera? like we have QR code and also selfie taking feature. Will it enough to mention that 'this app uses Camera for multiple feature'Ogre
Yes its same as you ask for location permission you need to define once and than you can use multiple times for multiple purposes, you need to have generic description for your permissions.Retractor

© 2022 - 2024 — McMap. All rights reserved.