iOS app camera access denied iOS 9.1(black screen)
Asked Answered
S

3

3

I want to access camera in my app. I am trying the following code.

  if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera])
            {
                UIImagePickerController *picker = [[UIImagePickerController alloc] init];
                picker.delegate = self;
                picker.allowsEditing = YES;
                picker.sourceType = UIImagePickerControllerSourceTypeCamera;
                if(isIOS8SystemVersion)
                {
                    [[NSOperationQueue mainQueue] addOperationWithBlock:^{
                        [self presentViewController:picker animated:YES completion:NULL];
                    }];
                }
                else
                {
                    [self presentViewController:picker animated:YES completion:NULL];
                }
            }

This code works on my other app perfectly.But in this app,it is not asking camera permissions or showing it in the settings->privacy->camera.

enter image description here

The app prompts to use the location.But not showing anything for the camera or photos.

The black screen appears and I can't take the picture if I directly use the camera code without the condition check.

Savona answered 14/12, 2015 at 6:23 Comment(9)
See this link for your solution: https://mcmap.net/q/537301/-idevice-camera-shows-black-instead-of-previewDownright
It doesn't work.I have tried this.Savona
which ios version you used?Downright
go to setting and scroll down and tap on your app. and verify that camera is shown or not?Downright
Not showing.I have added the image here.It is only showing location access.see the image.Its from my iPad.Savona
Let us continue this discussion in chat.Downright
Also stuck with this issue. did you solved it? @abhi1992Hoedown
Nop.Still facing the same issue.Working on that.Let me know if you got it cleared.Savona
@Hoedown check the answer by user5727805Savona
A
2

I had the exactly same issue for couple of days,

Try this its solved my problem, make sure that there is a value

(Application name as string) in your info.plist > "Bundle display name".

In my case it was empty and because of that it didn't work.

let me know if it helped you.

Argive answered 30/12, 2015 at 9:2 Comment(4)
YOu had issue only with ios9 devices?Savona
I had this issue with ios8 + ios9. and when i put a value (some string) in "Bundle display name" all was fixed. did you try it?Argive
Thanks a lot...Its working..Its been a month since I have been working on it.It was a great help.Savona
Happy to hear it, Good luck!Argive
L
1

Use following method to check device camera authorizationStatus. If not it will prompt for Access, if rejected if will show alert to navigate to App settings.

- (void)checkCameraPermission
{
    // *** check for hardware availability ***
    BOOL isCamera = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];
    if(!isCamera)
    {
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:APPName message:@"Camera not detected" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [alert show];

        return;
    }

    // *** Store camera authorization status ***
    AVAuthorizationStatus _cameraAuthorizationStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];

    switch (_cameraAuthorizationStatus)
    {
        case AVAuthorizationStatusAuthorized:
        {
            _cameraAuthorizationStatus = AVAuthorizationStatusAuthorized;
            // *** Camera is accessible, perform any action with camera ***
        }
            break;
        case AVAuthorizationStatusNotDetermined:
        {
            NSLog(@"%@", @"Camera access not determined. Ask for permission.");

            [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted)
             {
                 if(granted)
                 {
                     NSLog(@"Granted access to %@", AVMediaTypeVideo);
                    // *** Camera access granted by user, perform any action with camera ***
                 }
                 else
                 {
                     NSLog(@"Not granted access to %@", AVMediaTypeVideo);
                    // *** Camera access rejected by user, perform respective action ***
                 }
             }];
        }
            break;
        case AVAuthorizationStatusRestricted:
        case AVAuthorizationStatusDenied:
        {
            // Prompt for not authorized message & provide option to navigate to settings of app.
            dispatch_async( dispatch_get_main_queue(), ^{
                NSString *message = NSLocalizedString( @"My App doesn't have permission to use the camera, please change privacy settings", @"Alert message when the user has denied access to the camera" );
                UIAlertController *alertController = [UIAlertController alertControllerWithTitle:APPName message:message preferredStyle:UIAlertControllerStyleAlert];
                UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString( @"OK", @"Alert OK button" ) style:UIAlertActionStyleCancel handler:nil];
                [alertController addAction:cancelAction];
                // Provide quick access to Settings.
                UIAlertAction *settingsAction = [UIAlertAction actionWithTitle:NSLocalizedString( @"Settings", @"Alert button to open Settings" ) style:UIAlertActionStyleDefault handler:^( UIAlertAction *action ) {
                    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
                }];
                [alertController addAction:settingsAction];
                [self presentViewController:alertController animated:YES completion:nil];
            });
        }
            break;
        default:
            break;
    }
}
Liegeman answered 14/12, 2015 at 7:19 Comment(0)
D
0

The code works in my app :

UIImagePickerController *picker;
    if([self checkForCameraAcess]) 
    { 
    picker = [[UIImagePickerController alloc] init]; 
    picker.delegate = self; 
    picker.sourceType = UIImagePickerControllerSourceTypeCamera; 
    [self presentViewController:picker animated:YES completion:nil]; 
    } 
    else 
    { 
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Camera",nil) message:NSLocalizedString(@"Access to camera seems to be turned off. Please enable it from settings",nil) delegate:self cancelButtonTitle:NSLocalizedString(@"OK",nil) otherButtonTitles:NSLocalizedString(@"Settings",nil), nil]; 
    alert.tag = 101; 
    [alert show]; 
    }    

-(BOOL)checkForCameraAcess
{
    BOOL isAccess = YES;
    if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_1)
    {
        AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];

        //Here we check condition for AVAuthorizationStatusNotDetermined, because when user install iLeads app first time in device (Nerver before iLeads app install in Device), then setup an event and tap on the scan button, at that time authStatus is AVAuthorizationStatusNotDetermined so its show alert for camera acess first. Then after our custom alert shows if we tap on 'Dont allow' button of the camera acess.
        if(authStatus == AVAuthorizationStatusAuthorized || authStatus == AVAuthorizationStatusNotDetermined)
        {
            isAccess = YES;
        }
        else
        {
            isAccess = NO;
        }
    }
    return isAccess;
}

Don't forget to add UIImagePickerControllerDelegate in your .h

I hope it will work.

Downright answered 14/12, 2015 at 6:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.