Opening the Settings app from another app

2018-12-31 04:12发布

Okay, I know that there are many question about it, but they are all from many time ago.

So. I know that it is possible because the Map app does it.

In the Map app if I turn off the localization for this app, it send me a message, and if I press okay, the "Settings App" will be open. And my question is, how is this possible? How can I open the "Setting app" from my own app?

Basically I need to do the same thing, if the user turn off the location for my app, then I'll show him a message saying something that will open the "Setting app"

15条回答
孤独寂梦人
2楼-- · 2018-12-31 04:49

Swift 3:

guard let url = URL(string: UIApplicationOpenSettingsURLString) else {return}
if #available(iOS 10.0, *) {
  UIApplication.shared.open(url, options: [:], completionHandler: nil)
} else {
  // Fallback on earlier versions
  UIApplication.shared.openURL(url)
}
查看更多
有味是清欢
3楼-- · 2018-12-31 04:49

Swift 4

I prefer to open setting in a safer way,

if let settingUrl = URL(string:UIApplicationOpenSettingsURLString) {

    UIApplication.shared.open(settingUrl)
}
else {
    print("Setting URL invalid")
}
查看更多
笑指拈花
4楼-- · 2018-12-31 04:55

Swift You can use following function to open Settings App with Bluetooth Page

func openSettingsApp(){
    if let settings = NSURL(string: "prefs:root=Bluetooth") {
        UIApplication.sharedApplication().openURL(settings)
    }
}

Again this would not open the App's Settings. This would open settings app with Bluetooth as this is deep linking to bluetooth.

查看更多
登录 后发表回答