场景:app中保存图片时,会提示用户是否允许访问系统相册,如果 用户点了不允许,则以后保存图片时无法保存。下面代码提示用户去开启允许访问。
- (void)imageSavedToPhotosAlbum:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
if (!error) {
MBProgressHUD *HUD = [MBProgressHUD createHUD];
HUD.mode = MBProgressHUDModeCustomView;
HUD.label.text = @"保存成功";
[HUD hideAnimated:YES afterDelay:1.f];
} else {
// HUD.label.text = [NSString stringWithFormat:@"%@", [error description]];
if (error.code == -3310) {
//直接跳转到 【设置-隐私-照片】
UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"保存失败"
message:@"(请打开 设置-隐私-照片 来进行设置)"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"去开启" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=Privacy&path=PHOTOS"]];
}];
[alert addAction:cancelAction];
[alert addAction:okAction];
[self presentViewController:alert animated:YES completion:nil];
}
}
}
//隐私设置 @"prefs:root=Privacy&path=CAMERA",//设置相机使用权限 @"prefs:root=Privacy&path=PHOTOS"//设置照片使用权限 //常用设置 @"prefs:root=General&path=About",//关于本机 @"prefs:root=General&path=SOFTWARE_UPDATE_LINK",//软件更新 @"prefs:root=General&path=DATE_AND_TIME",//日期和时间 @"prefs:root=General&path=ACCESSIBILITY",//辅助功能 @"prefs:root=General&path=Keyboard",//键盘 @"prefs:root=General&path=VPN",//VPN设置 @"prefs:root=General&path=AUTOLOCK",//自动锁屏 @"prefs:root=General&path=INTERNATIONAL",//语言与地区 @"prefs:root=General&path=ManagedConfigurationList",//描述文件 //一级设置 @"prefs:root=WIFI",//打开WiFi @"prefs:root=Bluetooth", //打开蓝牙设置页 @"prefs:root=NOTIFICATIONS_ID",//通知设置 @"prefs:root=General", //通用 @"prefs:root=DISPLAY&BRIGHTNESS",//显示与亮度 @"prefs:root=Wallpaper",//墙纸 @"prefs:root=Sounds",//声音 @"prefs:root=Privacy",//隐私 @"prefs:root=STORE",//存储 @"prefs:root=NOTES",//备忘录 @"prefs:root=SAFARI",//Safari @"prefs:root=MUSIC",//音乐 @"prefs:root=Photos",//照片与相机 @"prefs:root=CASTLE"//iCloud @"prefs:root=FACETIME",//FaceTime @"prefs:root=LOCATION_SERVICES",//定位服务 @"prefs:root=Phone",//电话
其它(判断了用户拒绝了访问相册的权限):
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]; if (authStatus == AVAuthorizationStatusRestricted || authStatus ==AVAuthorizationStatusDenied) { //无权限 }
设置常用字段 http://m.blog.youkuaiyun.com/article/details?id=51425720