13

I can't get the "prefs" URL Scheme to work in iOS 10 (Beta 1).
It's set up correctly since the same App works fine on iOS 9.

Is this a bug or did it get renamed / removed?

Code:

let settingsUrl = NSURL(string: "prefs:root=SOMETHING")
if let url = settingsUrl {
    UIApplication.sharedApplication().openURL(url)
}

Update: (Beta 2)
Still not working in Beta 2.
It seams to be an bug. For example if you want do invite someone using GameCenter in iOS 10 and you're not logged into iMessage, you'll get a popup asking you to log in. But the "Settings" button does absolutely nothing.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
123FLO321
  • 854
  • 1
  • 7
  • 20

6 Answers6

19

Just replace prefs to App-Prefs for iOS 10

Below code works for iOS 8,9,10

Swift 3.0 and Xcode >= 8.1

if #available(iOS 10.0, *)
{
       UIApplication.shared.openURL(URL(string: "App-Prefs:root=SOMETHING")!)
}
else
{
       UIApplication.shared.openURL(URL(string: "prefs:root=SOMETHING")!)
}

Swift 2.2

if #available(iOS 10.0, *)
{
      UIApplication.sharedApplication().openURL(NSURL(string:"App-Prefs:root=SOMETHING")!)
}
else
{        
    UIApplication.sharedApplication().openURL(NSURL(string:"prefs:root=SOMETHING")!)
}

Works for me.

Happy Coding

Saumil Shah
  • 2,299
  • 1
  • 22
  • 27
4

You can use UIApplicationOpenSettingsURLString to open your own app's settings (this has been available since iOS 8) but any other prefs: URL is now considered a private API and use will result in app rejection.

Paulw11
  • 108,386
  • 14
  • 159
  • 186
  • Do you have a source link? – 123FLO321 Jul 26 '16 at 11:05
  • See http://stackoverflow.com/questions/38582888/when-i-was-in-use-prefs-root-wifi-by-apple-refused-to-act for one example. There are quite a few other questions here where the apps have been rejected for using it – Paulw11 Jul 26 '16 at 11:08
  • That sucks. Is there any other way to open any other Settings page than UIApplicationOpenSettingsURLString – 123FLO321 Jul 26 '16 at 11:40
4

You can use Prefs:root=SOMETHING

iOS 10 updated URL Scheme for Settings, you need to upcase the "p".

Ref: https://github.com/cyanzhong/app-tutorials/blob/master/schemes.md

NOTICE: It only works on Widgets, not works in Apps. (iOS 10.0.2)

@Saumil Shah's solution works in App, is more useful.

GeXiao
  • 41
  • 4
3

For the record, for Location services App-Prefs:root=Privacy&path=LOCATION worked for me. When I tested on a device and not a simulator.

I won't list the things I tried that did not work, it's a long list.

Usage example that assumes either location services are disabled or permission is denied or not determined:

if !CLLocationManager.locationServicesEnabled() {
    if let url = URL(string: "App-Prefs:root=Privacy&path=LOCATION") {
        // If general location settings are disabled then open general location settings
        UIApplication.shared.openURL(url)
    }
} else {
    if let url = URL(string: UIApplicationOpenSettingsURLString) {
        // If general location settings are enabled then open location settings for the app
        UIApplication.shared.openURL(url)
    }
}
Joe Susnick
  • 6,544
  • 5
  • 44
  • 50
2

This is not available on iOS 11, we can just open Settings like:

if let url = URL(string:UIApplicationOpenSettingsURLString) {
   if UIApplication.shared.canOpenURL(url) {
     UIApplication.shared.open(url, options: [:], completionHandler: nil)
   }
}
iCappsCVA
  • 47
  • 6
chawki
  • 867
  • 1
  • 8
  • 13
1

If anyone is interested in a "gray area" API, you can use:

//url = "prefs:root=SOMETHING"
[[LSApplicationWorkspace defaultWorkspace] openSensitiveURL:url withOptions:nil];

This will give you what you want. Hide it well, and it works in iOS 10.

Léo Natan
  • 56,823
  • 9
  • 150
  • 195
  • 2
    May I ask how to hide? – Andy Darwin Sep 19 '16 at 04:14
  • Hiding private API is not hard. Look into the Objective C runtime and how to use it with strings. You can then construct or encode these strings as you please. – Léo Natan Sep 19 '16 at 17:26
  • I import the LSApplicationWorkspace.h, and using your method [[LSApplicationWorkspace defaultWorkspace] openSensitiveURL:[NSURL URLWithString:@"prefs:root=LOCATION_SERVICES"] withOptions:nil]; When I compile to ipad, it will show is currently restricted and not eligible to open the scheme. log. Have you some example run on the ipad or iphone , not on the simulator ? I'm test the code on the simulator can work, but on the device is not working. – dickfala Sep 20 '16 at 13:45
  • Hmm, interesting. I did run on device, and it worked. It was in the latter betas. Maybe something changed in GM. I doubt it, because Apple uses this API to open various settings from their alerts. – Léo Natan Sep 20 '16 at 13:58
  • Did you have sample code on the github? I hope I can try your code in my device. Maybe that is my code have some fault ?! thank you – dickfala Sep 22 '16 at 13:01
  • No, sorry. I did it in my previous place of work - we needed to jump to the profile settings. No longer have access to that code. – Léo Natan Sep 22 '16 at 13:02
  • okey! thank you ~ I will still try to search other method. thanks. – dickfala Sep 22 '16 at 13:03
  • strange....but "prefs:root.." links do NOT work. while "Prefs:root..." (yes, initial capped) links DO work when doing this. in iOS 10. – crgt Dec 22 '16 at 00:11