I'm checking for permissions to the camera roll:
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:YES];
PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
if (status != PHAuthorizationStatusNotDetermined) {
// Access has not been determined.
[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
if (status == PHAuthorizationStatusAuthorized) {
// do something
}else {
// Access has been denied.
}
}];
}
}
And it works fine but the problem is if the user choose "Not Allow" and it wants to switch to "Allow".
How can the user switch the permission to the camera roll?
Your can ask your user to turn on the permission, if they say "yes, I want to turn on this permission" then you can transport them to your app's preferences in the Settings direct using NSURL, and they also can return to your app by click the back button in the status bar's left.
Here is code for transport user to your app's preferences:
NSURL *settingsUrl = [[NSURL alloc] initWithString:UIApplicationOpenSettingsURLString];
[[UIApplication sharedApplication] openURL:settingsUrl];
Here is full code I test in iOS10 iPhone6s:
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:YES];
PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
if (status != PHAuthorizationStatusNotDetermined) {
// Access has not been determined.
[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
if (status == PHAuthorizationStatusAuthorized) {
// do something
}else {
// Access has been denied.
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Need Photo Permission"
message:@"Using this app need photo permission, do you want to turn on it?"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *yesAction = [UIAlertAction actionWithTitle:@"YES" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
NSURL *settingsUrl = [[NSURL alloc] initWithString:UIApplicationOpenSettingsURLString];
[[UIApplication sharedApplication] openURL:settingsUrl];
}];
UIAlertAction *noAction = [UIAlertAction actionWithTitle:@"NO" style:UIAlertActionStyleCancel
handler:^(UIAlertAction * action) {
}];
[alert addAction:yesAction];
[alert addAction:noAction];
[self presentViewController:alert animated:YES completion:nil];
}
}];
}
}