Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective C - How to detect user has clicked Don't Allow access to photos button

I am using a UIImagePicker to present the users photos so that the user can choose an image to be used in my app.

My problem is that on the first time a user opens the image picker they are presented with a prompt saying: '"my App" Would like to Access your Photos' with two options, Don't allow and OK.

My requirement is that when the user clicks Don't Allow, the Image picker gets dismissed.

Is there a way to detect that the user has chosen Don't allow?

Currently it leaves the user in an ugly blank modal view. If the user opens the image picker again they are show the nice apple provided message that says "this app does not have access to your photos etc etc"

here is how I use the image picker:

self.imagePickerController = [[UIImagePickerController alloc] init];
self.imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:self.imagePickerController animated:YES];
like image 334
Robert Wagstaff Avatar asked Feb 07 '13 02:02

Robert Wagstaff


2 Answers

Got it!

if ([ALAssetsLibrary authorizationStatus] == ALAuthorizationStatusNotDetermined) {
    ALAssetsLibrary *assetsLibrary = [[ALAssetsLibrary alloc] init];
    [assetsLibrary enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
        if (*stop) {
            // INSERT CODE TO PERFORM WHEN USER TAPS OK eg. :
            return;
        }
        *stop = TRUE;
    } failureBlock:^(NSError *error) {
        // INSERT CODE TO PERFORM WHEN USER TAPS DONT ALLOW, eg. :
        self.imagePickerController dismissViewControllerAnimated:YES completion:nil];
    }];
}
like image 76
Robert Wagstaff Avatar answered Nov 14 '22 22:11

Robert Wagstaff


Use ALAssetsLibrary authorizationStatus. There is a specific return value that indicates your app has been denied.

Doing a search here on that method will reveal some sample code for properly handling the various authorization states.

like image 38
rmaddy Avatar answered Nov 14 '22 23:11

rmaddy