Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The "prefs" URL Scheme is not working in iOS 10 (Beta 1 & 2)

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.

like image 438
123FLO321 Avatar asked Jun 27 '16 23:06

123FLO321


4 Answers

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.

like image 167
Paulw11 Avatar answered Nov 14 '22 19:11

Paulw11


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 😊

like image 27
Saumil Shah Avatar answered Nov 14 '22 20:11

Saumil Shah


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.

like image 4
GeXiao Avatar answered Nov 14 '22 20:11

GeXiao


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)
    }
}
like image 3
Joe Susnick Avatar answered Nov 14 '22 19:11

Joe Susnick