-2

so I posted previously about this issue here.

As you can read I was rejected.

My question is how do I update this code to use openSettingsURLString instead of UIApplication.shared.openURL

After doing some asking and some research I found out I have to change this:

static func openSettingsAlert(_ title: String, message: String, settingsURL: String) -> UIAlertController {
let alertController = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert)

let settingsAction = UIAlertAction(title: "Settings", style: .default) { (_) -> Void in
    let settingsURL = URL(string: settingsURL)
    if let url = settingsURL {
        DispatchQueue.main.async(execute: {
            UIApplication.shared.openURL(url)
        })
    }
}

let cancelAction = UIAlertAction(title: "Cancel", style: .default, handler: nil)
alertController.addAction(cancelAction)
alertController.addAction(settingsAction)

return alertController
}

into code that uses this

But I'm so confused because I can't find that class anywhere, and if it's a class why is isn't the class capitalized?

How can I use it in the code snippet above.

I think it is a subclass of String, but I have no idea where to find this, or how to incorporate the change into the existing code safely.

Very confused on this and thank you for any insights.

TJBlack31
  • 745
  • 4
  • 8
  • 23

1 Answers1

0

I'm getting a Type 'UIApplication' has no member 'openSettingsURLString'

Well, you can see from the documentation that the type UIApplication does have this member. Here it is:

https://developer.apple.com/documentation/uikit/uiapplication/1623042-opensettingsurlstring

It is a static read-only property of UIApplication. (That is why it is not capitalized; it is a property.) And it is used like this:

let url = URL(string: UIApplication.openSettingsURLString)!
UIApplication.shared.open(url)

If you are not able to use it that way, it must be because you are using an outdated version of Swift. In that case, you would write:

let url = URL(string:UIApplicationOpenSettingsURLString)!
UIApplication.shared.open(url)

However, you should not be using such an outdated version of Swift. It is no crime, to be sure, but it certainly makes communication with the rest of us here on Stack Overflow difficult. By now, Xcode 10 and Swift 4.2 have been available for a long time, and you should upgrade to them so as to be on the same page with everyone else. Otherwise you're just trying to talk a different language from the rest of us — an older language that most of us have already forgotten. Not to mention the fact that you are out of sync with the online documentation, which does not show linguistic terms for older versions of the Swift language.

matt
  • 515,959
  • 87
  • 875
  • 1,141