繁体   English   中英

如何以编程方式打开设置应用程序?

[英]How to open settings app programmatically?

我在 ios 8.3 上使用 swift。 我想从我的应用程序中打开设置应用程序。 我知道使用代码

UIApplication.sharedApplication().openURL(NSURL(string: UIApplicationOpenSettingsURLString)!)

将打开我的应用程序设置。 但我不想打开我的应用程序设置。 我只想打开设置应用程序并停留在主页上。 如果可能,导航到“蜂窝网络”。 有没有办法实现这一目标?

尝试这个。

if let appSettings = URL(string: UIApplication.openSettingsURLString) {
    UIApplication.shared.open(appSettings, options: [:], completionHandler: nil)
}

Xcode 11.5 - iOS > 10

2016 年 10 月 11 日更新:

它不再适用于 iOS10。 到目前为止,我还没有找到任何解决方法。 如果你们有任何解决方案,请告诉我。 谢谢。

======================================

如果 iOS 版本 <= iOS9,则需要设置 URL 类型: 在此处输入图片说明

你可以这样做:

    let url:NSURL! = NSURL(string : "prefs:root=")
    UIApplication.sharedApplication().openURL(url)

我在github上有一个demo: http : //github.com/zhihuitang/SettingDemo.git

您可以找到所有可用的 URL,如下所示: http://iphonedevwiki.net/index.php/Preferences.app Preferences app 注册一个私有 URL 方案,prefs:,下面的列表详细说明打开特定视图1 [2]

prefs:root=General&path=About
prefs:root=General&path=ACCESSIBILITY
prefs:root=AIRPLANE_MODE
prefs:root=General&path=AUTOLOCK
prefs:root=General&path=USAGE/CELLULAR_USAGE
prefs:root=General&path=Bluetooth
prefs:root=General&path=DATE_AND_TIME
prefs:root=FACETIME
prefs:root=General
prefs:root=General&path=Keyboard
prefs:root=CASTLE
prefs:root=CASTLE&path=STORAGE_AND_BACKUP
prefs:root=General&path=INTERNATIONAL
prefs:root=LOCATION_SERVICES
prefs:root=ACCOUNT_SETTINGS
prefs:root=MUSIC
prefs:root=MUSIC&path=EQ
prefs:root=MUSIC&path=VolumeLimit
prefs:root=General&path=Network
prefs:root=NIKE_PLUS_IPOD
prefs:root=NOTES
prefs:root=NOTIFICATIONS_ID
prefs:root=Phone
prefs:root=Photos
prefs:root=General&path=ManagedConfigurationList
prefs:root=General&path=Reset
prefs:root=Sounds&path=Ringtone
prefs:root=Safari
prefs:root=General&path=Assistant
prefs:root=Sounds
prefs:root=General&path=SOFTWARE_UPDATE_LINK
prefs:root=STORE
prefs:root=TWITTER
prefs:root=General&path=USAGE
prefs:root=VIDEO
prefs:root=General&path=Network/VPN
prefs:root=Wallpaper
prefs:root=WIFI
prefs:root=INTERNET_TETHERING

希望这对你有帮助。

是的,他们在 iOS 10 中进行了更改,请将“prefs:”更改为“App-Prefs:”

guard let profileUrl = URL(string:"App-Prefs:root=General&path=ManagedConfigurationList") else {
    return
}

if UIApplication.shared.canOpenURL(profileUrl) {
    UIApplication.shared.open(profileUrl, completionHandler: { (success) in
        print(" Profile Settings opened: \(success)")
    })
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM