Reputation: 1647
Just trying to add location services to my app (in ObjC). I only want the permissions prompt to appear when I am about to use it, however the prompt appears when I first open the app.
My impression was that the prompt would only appear when startUpdatingLocation
was called on the CLLocationManager
object. However this is only called in my app on certain ViewControllers (definitely not my first view controller).
Interestingly this issue only appears in iOS8, it's fine in iOS7. Anyone had a similar issue? Or have any idea what else could be wrong?
Thanks.
Upvotes: 1
Views: 747
Reputation: 27598
Without knowing where you had placed your code, the way I would approach this issue is
This should take care of your prompt on app launch
UPDATE: Your app will prompt for location access right on startup on iOS 8. This is because the "Required background modes" required key is detected in plist file. The only thing you can do is make that message more descriptive as to why you need access. Add this key and description pair to your plist file and add whatever explanation text you like in it
NSLocationWhenInUseUsageDescription Please grant this app access to your location incase of failed login attempts are detected and you want to know who it was
Upvotes: 1
Reputation: 1313
iOS 8 changes how location services are handled, and it also means that if you're supporting older versions of the OS you potentially need to do some extra coding. For an wonderfully detailed look at the entire process, checkout NSHipster
Prior to iOS 8, yes calling startUpdatingLocation
would prompt the user for permission. Though now requesting permission and starting the location updates are separate and you'll need to call requestWhenInUseAuthorization
or requestAlwaysAuthorization
.
Not only that, but in iOS8 you need to explicitly add two plist keys and then define their values: NSLocationWhenInUseUsageDescription
and NSLocationAlwaysUsageDescription
, which are strings that will show up in the alert that notifies users that your app is requesting location information.
But seriously, check out the link. It's phenomenal at explaining this all, far better than I could summarize here.
Upvotes: 2