Request permissions again after user denies location services?

TruMan1 picture TruMan1 · May 1, 2015 · Viewed 28.2k times · Source

I track the user's location and ask for permission when my load first loads using this:

locationManager.requestAlwaysAuthorization()
locationManager.startUpdatingLocation()

If the user denies, but later changes their mind by enabling the configuration option in my app, how do I ask again? For example, I have a switch for auto detecting the user's location so when they enable it, I am trying to do this:

@IBAction func gpsChanged(sender: UISwitch) {
    // Request permission for auto geolocation if applicable
    if sender.on {
        locationManager.requestAlwaysAuthorization()
        locationManager.startUpdatingLocation()
    }
}

But this code doesn't seem to do anything. I was hoping it would ask the user again if they want to allow the app to track the user's location. Is this possible?

Answer

bgilham picture bgilham · May 1, 2015

The OS will only ever prompt the user once. If they deny permission, that's it. What you can do is direct the user to the Settings for your app by passing UIApplicationOpenSettingsURLString to UIApplication's openURL: method. From there, they can re-enable location services if they wish. That said, you probably shouldn't be too aggressive about bugging them for the permission.