Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build a Restaurant Reviews App Obtaining a Location Fix Responding to Delegate Events

Qasa Lee
Qasa Lee
18,916 Points

Figured out a way to present an alert and jump to "Settings"

I figured out a way to pop out an alert and jump to settings if user tapped "Don't allow". Below comes my code:

func authorizationFailedWithStatus(_ status: CLAuthorizationStatus) {
        // Show an alert
        let alertController = UIAlertController(title: "What? Disallowed!?", message: "Are you serious???", preferredStyle: UIAlertControllerStyle.alert)

        alertController.addAction(UIAlertAction(title: "OK Jump to Settings", style: .default, handler: { (action) in // "action" never being used in this closure, is there a way to improve this?!
            if let settingsURL = URL(string: UIApplicationOpenSettingsURLString + Bundle.main.bundleIdentifier!) {
                UIApplication.shared.open(settingsURL, options: [:], completionHandler: nil)
            }
        }))

        self.present(alertController, animated: true, completion: nil)

    }

BTW: this is on Xcode 9 and Swift 4. This code might help, although I believe there's a better way for sure.

Ryan Morrison
Ryan Morrison
6,195 Points

You are a star. Thank you. This is brilliant.