JohnnL
JohnnL

Reputation: 111

How to make an app to have location service option "while using the app"?

I have an app which has location service enabled. But it doesn't have the option "while using the app" even the app's SDK is iOS 8.2. Does anyone know how to fix it? Thanks in advance!

Upvotes: 1

Views: 538

Answers (2)

JohnnL
JohnnL

Reputation: 111

I found the answer from another post. Basically, I need to add the following key to the info.plist file:

NSLocationWhenInUseUsageDescription

Also, the following code needs to be called:

if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
    [self.locationManager requestWhenInUseAuthorization];
}

Upvotes: 0

markdanyo
markdanyo

Reputation: 31

In order to support both "While Using the App" and "Always" authorization in your app's Location settings, you must call both [CLLocationManager requestWhenInUseAuthorization] and [CLLocationManager requestAlwaysAuthorization] at some point in your app.

Remember that despite requesting authorization twice, only one alert dialog will be presented to the user per install of the app, corresponding to the authorization type you request first. The only way for the user to subsequently update the status is via the Settings app.

Upvotes: 1

Related Questions