English 中文(简体)
ALAssetsLibrary ALAssetsLibraryAccessUserDeniedError
原标题:

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?

最佳回答

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.

问题回答

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... 
Enable 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... 
Enable 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];
    }
}




相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签