iOS

通过 openURL 方法跳转至设置 - iOS

2019-03-15  本文已影响0人  survivorsfyh

iOS 10 以下系统版本可以通过 openURL 的方式跳转至指定的设置界面,code 如下:

NSURL *url = [NSURL URLWithString:@"prefs:root=LOCATION_SERVICES"];// iOS 10 弃用
if( [[UIApplication sharedApplication] canOpenURL:url]) {
    [[UIApplication sharedApplication] openURL:url];
}

跳转至具体各个功能模块对应的参数如下:

    About — prefs:root=General&path=About
 
    Accessibility — prefs:root=General&path=ACCESSIBILITY
 
    Airplane Mode On — 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 Volume Limit — 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
 
    Software Update — 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

iOS 10 以上系统版本运行异常如下:

-canOpenURL: failed for URL: "prefs:root=LOCATION_SERVICES" - error: "The operation couldn’t be completed. (OSStatus error -10814.)"

解决办法,改成跳转至系统设置页面,完后再进行对应的配置选项进行设置,code 如下:

NSURL *url = [[NSURL alloc] initWithString:UIApplicationOpenSettingsURLString];// 跳转至系统设置
//NSURL *url = [NSURL URLWithString:@"prefs:root=LOCATION_SERVICES"];// iOS 10 弃用
if( [[UIApplication sharedApplication] canOpenURL:url]) {
    [[UIApplication sharedApplication] openURL:url];
}

以下是以位置访问权限为例写的例子,仅以此参考.

GitHub


以上便是此次内容的小结,希望能对大家有所帮助!

上一篇下一篇

猜你喜欢

热点阅读