ALAssetsLibrary ALAssetsLibraryAccessUserDeniedError

When you first try to access a custom ALAssetsLibrary, the OS will present them with a dialog asking for permission. If they do not allow this, failBlock will be called in the future and will always be called in the future. Is there a way to call this authorization request again?

In the Maps app, I noticed that they tell the user to go to the Settings app to enable location services using a button. However, I do not know how to open the Settings application programmatically. Should I just show directions on how to enable location services?

+5
source share
2 answers

Cannot open the settings application in Apple-approved form. The best you can hope for is to grab the error and then display a UIAlertView or other view with instructions on how to do this. Take a look at the latest Dropbox app to understand how they instruct the user.

+6
source

When you try to access the Library from your code, you can use the error handler to catch the error and display a warning telling the user what to do.

Example

failureBlock:^(NSError *error) {
    // error handling
    if (error.code == ALAssetsLibraryAccessGloballyDeniedError) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error!" 
            message:@"Error loading image... \nEnable Location Services in 'Settings -> Location Services'." 
            delegate:self cancelButtonTitle:@"OK" 
            otherButtonTitles:nil, nil];
        [alert show];
    } else if (error.code == ALAssetsLibraryAccessUserDeniedError) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error!" 
            message:[NSString stringWithFormat:@"Error loading image... \nEnable Location Services in 'Settings -> Location Services' for %@.", [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"]] 
            delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [alert show];
    } else {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error!" message:@"Error loading image..." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [alert show];
    }
}
0
source

All Articles