Pergunta

When you first try to access a user's ALAssetsLibrary, the OS will present them with a dialog asking for permission. If they do not allow this, a failureBlock will be called and will always be called in the future. Is there a way to force a prompt of this authorization request again?

I notice in the Maps app, that they inform the user to go to the Settings app to turn on location services with a button. However, there is no way that I know of to programmatically open the Settings app. Should I just display directions as to how to turn on the location services?

Foi útil?

Solução

You can't open up the settings app in an Apple approved manner. The best you can hope for is to trap the error and then display a UIAlertView or other view with instructions on how to do this. Take a look at the latest v. of the Dropbox app for an idea on how they instruct the user.

Outras dicas

When you try to access the Library from your code, you can use the error handler to catch the error and display an alert specifying to 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];
    }
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top