Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asking camera permission on iPad

Tags:

ios

ipad

camera

In an app, I'm currently taking a picture only after camera permissions have been checked, as follows:

AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
if(authStatus == AVAuthorizationStatusAuthorized) {
    // Take picture
}else{
    // Prompt user to go into their settings and add permissions for app
}

However, on first use, a) the initial "Would you like to give this app camera permissions?" prompt does not appear, and b) the app doesn't appear in the iPad's settings under privacy -> camera. This leads to the unfortunate case of not being able to ever allow camera permissions in the app.

Any suggestions on how to avoid this would be much appreciated. Thanks for reading.

like image 598
Rogare Avatar asked Dec 13 '25 08:12

Rogare


1 Answers

You need to request for permission using the following code:

AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
if(authStatus == AVAuthorizationStatusAuthorized)
{
    // Take picture
}
else
{
    [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted)
    {
       if (granted)
       {
           NSLog(@"User Granted");
       }
       else
       {
           NSLog(@"User Denied");
       }
    }];
}
like image 185
Midhun MP Avatar answered Dec 16 '25 09:12

Midhun MP



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!