0

got the below issue in my application..i got below issue iOS 10 only. before versions the issue is not replicated.

1) Install/Reinstall the my iOS build. 2) Go to media items --> Images/video. 3) While using "Take photo" and "Take Video" option at very first time, it will ask the permission to take the photo/video. Now confirm the permission.

Issue: Once the confirm the permission it should be in camera screen, but still it is in my application app screen.

I am adding “Privacy - Camera Usage Description” in info.plist. but still getting same issue.

My Code:

AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];

if (authStatus == AVAuthorizationStatusAuthorized) 

{

// do your logic

UIImagePickerController *imagePickController = [[UIImagePickerController alloc]init];

if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) 

{
                    imagePickController.sourceType = UIImagePickerControllerSourceTypeCamera;

imagePickController.delegate = self;

imagePickController.allowsEditing = NO;

imagePickController.showsCameraControls = YES;

[[NSOperationQueue mainQueue] addOperationWithBlock: ^{

[UIApplication sharedApplication].statusBarHidden = YES;

[self presentViewController:imagePickController animated:YES completion:nil];

}];

}

else {

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"CAMERA_NOTAVAILABLE", nil) message:nil delegate:nil cancelButtonTitle:nil otherButtonTitles:LOC(@"ok"), nil];

[alertView show];

[alertView setTag:Camera_Access_TAG];

}
Surya
  • 151
  • 2
  • 14

4 Answers4

0

Use this function to check the permission before presenting camera:

func checkForCameraAccess() -> Bool{
    let authStatus = AVCaptureDevice.authorizationStatus(forMediaType: AVMediaTypeVideo)
    switch authStatus {
    case .authorized: return true
    case .denied: return false
    case .notDetermined: return false
    default: return false
    }
}

This will solve the issue.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Arun Kumar
  • 34
  • 4
  • i am editing my question. please check it once.. and give me in objective c.. i have no idea in swift – Surya Mar 20 '17 at 07:00
0

You might not doing anything at time of requesting permission. So write you code as below. To request permission

[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted)
             {
                 if(granted)
                 {
                     //Use your authorised code here
                 }

             }];
sschunara
  • 2,285
  • 22
  • 31
0

Sorry if i am mistaken, your question seems different and your code saying different scenario.

If you want to get Media from Photo Library (As you have mentined in question)

Privacy - Camera Usage Description - This permission will let user ask for permission to access device camera not photo library.

If you want to open photo library, you must include

NSPhotoLibraryUsageDescription

Here is the link to all Information Property List Key Reference by Apple. https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html

and change your source to

  • UIImagePickerControllerSourceType.savedPhotosAlbum
  • UIImagePickerControllerSourceType.photoLibrary

Or If the question is just about accessing camera and it permission Here is answer: https://stackoverflow.com/a/20464727

Community
  • 1
  • 1
Devang Tandel
  • 2,988
  • 1
  • 21
  • 43
0

For swift 3.0.1:

if PHPhotoLibrary.authorizationStatus() == .authorized {
    print("authorized")

} else {
    print("Not authorized")
    AVCaptureDevice.requestAccess(forMediaType: AVMediaTypeVideo) { response in
    if response {
        //access granted
        print("AV access")
    } else {
        print("AV Denied Permission")
    }
   }
}
Sour LeangChhean
  • 7,089
  • 6
  • 37
  • 39