objective-ccard.ioios10xcode8-beta2

requestAccessForMediaType crashing in iOS 10


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 ?


Solution

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