Instance Method

locationManager(_:didChangeAuthorization:)

Tells the delegate its authorization status when the app creates the location manager and when the authorization status changes.

Declaration

optional func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus)

Parameters

manager

The location manager object reporting the event.

status

The authorization status for the app.

Discussion

The system calls this method when the app creates the related object's CLLocationManager instance, and when the app's authorization status changes. The status informs the app whether it can access the user's location.

Use this delegate method to manage your app's state changes in response to its ability to use location information. For example, you may wish to enable or disable your app's location-related features, as appropriate.

If the user's choice doesn't change the authorization status after you call the requestWhenInUseAuthorization() or requestAlwaysAuthorization() method, the location manager does not report the current authorization status to this method—the location manager only reports changes. For example, the location manager calls this method when the status changes from CLAuthorizationStatus.notDetermined to CLAuthorizationStatus.authorizedWhenInUse.

Events that Cause Authorization Status Changes

An app's authorization status changes in response to users' actions. Users can change permission for apps to use location information at any time. The user can:

  • Change an individual app's location authorization in Settings > Privacy > Location Services, or in Settings > (the app) > Location Services.

  • Turn location services on or off globally in Settings > Privacy > Location Services.

  • Choose Reset Location & Privacy in Settings > General > Reset.

A user's response to location manager prompts can also change authorization status. For instance, users may change the authorization status by responding to the prompts initiated by calls to requestWhenInUseAuthorization() or requestAlwaysAuthorization() methods. For apps with Always authorization, users may change the authorization status to When In Use when responding to the location usage reminder alert.

When an app has temporary authorization, the authorization changes when the user ceases to use the app.