Opening the Settings app from another app

前端 未结 17 2193
傲寒
傲寒 2020-11-22 01:37

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 M

相关标签:
17条回答
  • 2020-11-22 02:17

    From @Yatheeshaless's answer:

    You can open settings app programmatically in iOS8, but not in earlier versions of iOS.

    Swift:

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

    Swift 4:

    if let url = NSURL(string: UIApplicationOpenSettingsURLString) as URL? {
        UIApplication.shared.openURL(url)
    }
    

    Swift 4.2 (BETA):

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

    Objective-C:

    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
    
    0 讨论(0)
  • 2020-11-22 02:17

    SWIFT 4.0

    'openURL' was deprecated in iOS 10.0: Please use openURL:options:completionHandler: instead

    UIApplication.shared.open(URL.init(string: UIApplicationOpenSettingsURLString)! , options: [:], completionHandler: nil)
    
    0 讨论(0)
  • 2020-11-22 02:19

    To add to accepted answer: (from apple developer documentation) "When you open the URL built from this string (openSettingsURLString), the system launches the Settings app and displays the app’s custom settings, if it has any." So, if you want to open settings for your app, create your own Settings.bundle.

    0 讨论(0)
  • 2020-11-22 02:23

    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.

    0 讨论(0)
  • 2020-11-22 02:24

    In Swift 3 / iOS 10+ this now looks like

    if let url = URL(string: "App-Prefs:root=LOCATION_SERVICES") {
        UIApplication.shared.open(url, completionHandler: .none)
    }
    
    0 讨论(0)
提交回复
热议问题