Search code examples
swift3settingsicloudios10openurl

"prefs:root=CASTLE" not working to open iCloud Settings in IOS10?


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?


Solution

  • 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)
        }
    }