Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

Qasa Lee
Qasa Lee
18,915 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.