0

I currently have my app setup to request location services always, using [locationManager requestAlwaysAuthorization]; and NSLocationAlwaysUsageDescription

This works fine, however I would like to give the option of using location services only while using the app like in the screenshot below.

I have tried adding NSLocationWhenInUseUsageDescription however this overides he always request and only gives the alert for while in use, any ideas on who to give both options in settings?

Sami
  • 1,374
  • 1
  • 16
  • 43
  • 2
    possible duplicate of [iOS: Core Location is not asking user's permission while installing the app. getting kCLAuthorizationStatusNotDetermined every time](http://stackoverflow.com/questions/20664928/ios-core-location-is-not-asking-users-permission-while-installing-the-app-get) – rkyr Sep 11 '15 at 09:43

2 Answers2

0

First ask the user using your own dialog with two options - always / when using the app. Then call appropriate permission request according to the user's choice.

Either:

[locationManager requestAlwaysAuthorization];

or:

[locationManager requestWhenInUseAuthorization];

having both in plist is valid so that's not a problem. Depends on when you actually request it in the code.

It will be slightly tricky to maintain though, so a good code structure is crucial.

Michal
  • 15,429
  • 10
  • 73
  • 104
  • I have it working for 'always', but I want the user to be able to go into location services settings and change to 'while in use', I've read requesting location services twice once for each won't work as the alert is only ever shown once. – Sami Sep 11 '15 at 09:41
  • Also if I had both keys to info.plist only the whole in use notification is called not the always one which is the one I want called. – Sami Sep 11 '15 at 09:42
  • Well if you want to change where you've already asked, that might be a problem. My suggested solution is for "new" users only. Where you've already shown the dialogue you can't do anything...other than going your own way - own dialogue explaining what the user needs to do. – Michal Sep 11 '15 at 09:44
0

The built in iOS alert will only allows for one level of permission and it will only ask the user once. The assumption is that most apps will only need one or the other. In any case, if you want to have both options show up in the Settings, you must ask for Always permission.

More importantly though: The Always setting is really only to be used by apps that require background location updates. So unless your app requires it, you shouldn't be asking for it. Also, using background location mode will cause your app to be more heavily scrutinized during the app review process.

rmp
  • 3,503
  • 1
  • 17
  • 26