Instance Method

requestAlwaysAuthorization

Requests the user’s permission for location services whether or not the app is in use.

Declaration

- (void)requestAlwaysAuthorization;

Discussion

You must call this method or the requestWhenInUseAuthorization method before you can receive location information. You may call requestAlwaysAuthorization when the current authorization state is either:

The requestAlwaysAuthorization method runs asynchronously. It prompts the user to grant permission to the app to use location services at any time, including when the user doesn’t know the app is running. To call this method, you must have NSLocationAlwaysUsageDescription and NSLocationWhenInUseUsageDescription keys in your app’s Info.plist file.

This method displays two prompts: an initial prompt, and a second prompt that appears only after an event occurs that requires Always authorization. The initial prompt uses the purpose string from the NSLocationWhenInUseUsageDescription key. The second prompt uses the purpose string from the NSLocationAlwaysUsageDescription key.

After the user responds to the initial prompt, your app receives one of the following states:

Provisional Always

In this state, your app receives Always authorization in locationManager:didChangeAuthorizationStatus:. However, when an event occurs that requires Always authorization, the system displays the second prompt. Users can decide at that time whether to grant (permanent) Always or When In Use authorization.

Temporary When in Use

Expires when your app is no longer in use.

Denied

Core Location allows no further authorization requests.

Receive Permanent Always Authorization

Your app can receive permanent Always authorization if the user chooses to grant permission when the second prompt appears during the Provisional Always state. Your app will receive the following calls to your delegate’s locationManager:didChangeAuthorizationStatus: method:

  • If the user chooses Always authorization, the system doesn’t call your delegate because it already has (provisional) Always authorization. Core Location removes the provisional status, making the Always authorization permanent and your app receives the location event.

  • If the user chooses When In Use authorization, the system calls your delegate with When In Use authorization. Your app does not receive the location event.

Your app can no longer ask for Always authorization after the user responds to this prompt. Calling this method again will have no effect.

See Also

Requesting Authorization for Location Services

- requestWhenInUseAuthorization

Requests the user’s permission to use location services while the app is in use.

CLAuthorizationStatus

Constants indicating the app's authorization to use location services.

+ authorizationStatus

Returns the app’s authorization status for using location services.