guru
guru

Reputation: 2817

How to dismiss imagePicker when user don't allow access in iOS

I am checking camera and photo permission on my App when user select or capture any image. I am using this code.

-(void)choosePhotoFromExistingImages
 {   
    ALAuthorizationStatus status = [ALAssetsLibrary authorizationStatus];
    if (status == ALAuthorizationStatusDenied  || status == ALAuthorizationStatusRestricted) {
        [APPDELEGATE showAlertViewForPhotos];
        //show alert for asking the user to give permission    
    }
    else{
        if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypePhotoLibrary])
        {
            UIImagePickerController *controller = [[UIImagePickerController alloc] init];
            controller.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
            controller.allowsEditing = YES;
            controller.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeImage, nil] ;
            controller.delegate = self;
            [self presentViewController: controller animated: YES completion: nil];
        }
    }   
}

The code is working fine but when user first time choose Don't allow photo library it display a black screen like this same thing happening in camera. What i need is that when user press on don't allow i can check that user has cancel the permission so i can dismiss imagepicker or camera .enter image description here

Upvotes: 1

Views: 1450

Answers (1)

Proton
Proton

Reputation: 1365

You can use ALAssetsLibrary authorizationStatus to check it

How do I react to a user choosing "Don't Allow" when asking for permission to access Photos?

Upvotes: 3

Related Questions