简体   繁体   中英

Asking camera permission on iPad

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.

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");
       }
    }];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM