1

In my app I have an alert view that has an option to open the iCloud section of the IOS Settings app. This previously worked on IOS8/9 (Swift 2):

let settingsCloudKitUrl = URL(string:"prefs:root=CASTLE")
if let url = settingsCloudKitUrl {
    UIApplication.sharedApplication().openURL(url)
}

In IOS10 (Swift 3) it isn't working anymore, because openURL() has been deprecated. I changed my code to the following:

let settingsCloudKitUrl = URL(string:"prefs:root=CASTLE")
if let url = settingsCloudKitUrl {
    if #available(iOS 10, *) {
        if UIApplication.shared.canOpenURL(url) {
            UIApplication.shared.open(url, options: [:], completionHandler: nil)
        }
    } else {
        UIApplication.shared.openURL(url)
    }
}

But the above code is not working for IOS10. UIApplication.shared.canOpenURL(url) returns false. What do I have to change to get this working again in IOS10?

Leontien
  • 612
  • 5
  • 22
  • `prefs:` will NOT work since iOS 10. use `UIApplicationOpenSettingsURLString` – LC 웃 Oct 30 '16 at 15:20
  • UIApplicationOpenSettingsURLString will open the section of my app in the IOS Settings app. That's is not what I want. I need the iCloud section to open in the Settings app. – Leontien Oct 30 '16 at 15:33
  • prefs was an private API...Apple recommends you to use UIApplicationOpenSettingsURLString ....to open settings of your app – LC 웃 Oct 30 '16 at 15:39
  • 3
    Again: I do not want to open the settings of my own app! I want to open the iCloud Settings section. – Leontien Oct 30 '16 at 15:42

1 Answers1

0

For iOS 10 onwards change prefs:root=CASTLE to App-Prefs:root=CASTLE and this will work fine

let settingsCloudKitUrl = URL(string:"App-Prefs:root=CASTLE")
if let url = settingsCloudKitUrl {
    if #available(iOS 10, *) {
        if UIApplication.shared.canOpenURL(url) {
            UIApplication.shared.open(url, options: [:], completionHandler: nil)
        }
    } else {
        UIApplication.shared.openURL(url)
    }
}
Mahesh Narla
  • 342
  • 2
  • 3
  • 20