Search code examples
iosswifttoday-extension

Open Settings app from Today Extension/Widget?


Is it possible to directly open the Settings app from the widget/today extension?

I have tried the following code, but sadly it is not working

let url = URL(string:UIApplicationOpenSettingsURLString)!
extensionContext?.open(url) { _ in }

Solution

  • this code should be work

    
            guard let url = URL(string: UIApplicationOpenSettingsURLString) else {
                return
            }
            extensionContext?.open(url, completionHandler: { (success) in
                if !success {
                    var responder = self as UIResponder?
    
                    while (responder != nil){
                        let selectorOpenURL = NSSelectorFromString("openURL:")
                        if responder?.responds(to: selectorOpenURL) == true {
                            _ = responder?.perform(selectorOpenURL, with: url)
                        }
                        responder = responder?.next
                    }
                }
            })
    

    however I'm not sure what "additional review" means enter image description here