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?
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
toUIApplication
'sopenURL:
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.You only get one chance. For the user to enable permissions after denying them, they have to go through the Settings app. See Requesting Permission to Use Location Services in CLLocationManager.
The permission pop up only shows once. So we have to redirect users to Settings after that. Here comes the code in Swift:
You can have an alternate solution!! You can show your own alert with the better message which can convince your user to allow to receive push notifications for your app. If user allows, then only you show default permission alert for enable push notification otherwise if user disallows, don't show default alert in-fact, you can save corresponding flag in your database or NSUserDefaults and can ask user later on again and again on some events in your app.