如何在APP内跳转设备设置指定页面

为迎合项目需求,在个人推广二维码的时候添加长按保存图片到相册的功能.但是,往往有部分用户在使用的时候会拒绝程序访问照片,导致后期保存图片失败...好了,既然有这一需求,那就有相应实现.首先找到Info.plist,在URL types下添加相应的URL Schemes,如下图所示:

添加url schemes


实现方法如下,可以直接复制,复制前请先引入系统库#import <AssetsLibrary/AssetsLibrary.h>

- (void)image:(UIImage *)image didFinishSavingWithError:(NSError*)error contextInfo:(void*)contextInfo

{

if (error){

ALAuthorizationStatus author = [ALAssetsLibrary authorizationStatus];

if (author == kCLAuthorizationStatusRestricted || author ==kCLAuthorizationStatusDenied){

//无访问权限

CustomAlertController *alert = [CustomAlertController alertControllerWithTitle:@"提示" message:@"保存失败!请在设备的“设置-隐私-照片”中允许程序访问你的照片。" preferredStyle:UIAlertControllerStyleAlert];

[self presentViewController:alert animated:YES completion:^{

alert.OKAction = ^{

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=Privacy&path=PHOTOS"]];

};

}];

}else{

[MBProgressHUD showMessage:error.localizedRecoverySuggestion view:self.view];

}

}else {

[MBProgressHUD showSuccess:@"保存成功" toView:self.view];

}

}

跳转设置的字段

About — prefs:root=General&path=About

Accessibility — prefs:root=General&path=ACCESSIBILITY

AirplaneModeOn— prefs:root=AIRPLANE_MODE

Auto-Lock — prefs:root=General&path=AUTOLOCK

Brightness — prefs:root=Brightness

Bluetooth — prefs:root=General&path=Bluetooth

Date& Time — prefs:root=General&path=DATE_AND_TIME

FaceTime — prefs:root=FACETIME

General— prefs:root=General

Keyboard — prefs:root=General&path=Keyboard

iCloud — prefs:root=CASTLE  iCloud

Storage & Backup — prefs:root=CASTLE&path=STORAGE_AND_BACKUP

International — prefs:root=General&path=INTERNATIONAL

Location Services — prefs:root=LOCATION_SERVICES

Music — prefs:root=MUSIC

Music Equalizer — prefs:root=MUSIC&path=EQ

Music VolumeLimit— prefs:root=MUSIC&path=VolumeLimit

Network — prefs:root=General&path=Network

Nike + iPod — prefs:root=NIKE_PLUS_IPOD

Notes — prefs:root=NOTES

Notification — prefs:root=NOTIFICATIONS_ID

Phone — prefs:root=Phone

Photos — prefs:root=Photos

Profile — prefs:root=General&path=ManagedConfigurationList

Reset — prefs:root=General&path=Reset

Safari — prefs:root=Safari  Siri — prefs:root=General&path=Assistant

Sounds — prefs:root=Sounds

SoftwareUpdate— prefs:root=General&path=SOFTWARE_UPDATE_LINK

Store — prefs:root=STORE

Twitter — prefs:root=TWITTER

Usage — prefs:root=General&path=USAGE

VPN — prefs:root=General&path=Network/VPN

Wallpaper — prefs:root=Wallpaper

Wi-Fi — prefs:root=WIFI

Setting—prefs:root=INTERNET_TETHERING

注:

系统版本 >= 10.0时

NSURL*url = [NSURLURLWithString:UIApplicationOpenSettingsURLString];

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容