Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS App crashes when user denies permission to Photos after Move & Scale in UIImagePickerController

I am using the default UIImagePickerController with allowsEditing set to YES for taking photo. When the user moves and scales the photo, the OS asks for access to 'Photos'. The app crashes if the user denies access.

- (void)openCamera
{
    UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
    imagePickerController.editing = YES;
    imagePickerController.allowsEditing = YES;
    imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
    imagePickerController.delegate = self;
    [self presentViewController:imagePickerController animated:YES completion:nil];
}

And UIImagePickerControllerDelegate method goes like

- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

    UIImage *image = info[UIImagePickerControllerEditedImage];
    if (!image) {
        image = info[UIImagePickerControllerOriginalImage];
    }

    self.profileImage = image;

    [picker dismissViewControllerAnimated:YES completion:nil];
}

Crash message:

*** This application is not allowed to access Photo data.

I'm wondering why it should ask for access to Photos in the first place. Any thoughts?

like image 355
Ramsundar Shandilya Avatar asked Jan 12 '15 23:01

Ramsundar Shandilya


1 Answers

Use Assets Framework to test if your app is allowed to access photo data.

  ALAuthorizationStatus status = [ALAssetsLibrary authorizationStatus];

  if(status==ALAuthorizationStatusAuthorized) {
        ..your code...
  }
like image 119
Emmanuel Crombez Avatar answered Oct 08 '22 08:10

Emmanuel Crombez