Location access - App is not asking for user permission to access location - iOS 11
I have gone through the Apple documentation and found the solution for this question.
Apple has changed few guidelines to get user location.
Here is the Video Link: Apple- What's New in Location Technologies
Full code for location access in Swift & Objective-C both
Solution:
Now we need to add three Authentication Key into Plist:
- NSLocationAlwaysAndWhenInUseUsageDescription
- NSLocationWhenInUseUsageDescription
- NSLocationAlwaysUsageDescription
Plist will look like :
And Authentication message screen will look like:
Full code for location access
iOS: App is not asking user's permission while installing the app. getting kCLAuthorizationStatusNotDetermined every time - Objective-c & Swift
I was facing the same issue, after re-installing my app it was returning kCLAuthorizationStatusNotDetermined
whenever checking for [CLLocationManager authorizationStatus]
and the app didn't even show up in Settings > Privacy > Location Services.
The authorization dialog that iOS prompts user to approve access to location services is triggered on [locationManager startUpdatingLocation]
which in your case is never called (shouldFetchUserLocation
will be always NO
).
Miguel C.'s solution seems like a good fix, will try that.
Edit for iOS8.x
When iOS8 came it brought little change in the way CLLocationManager is used. As mentioned few times in other answers it requires additional step comparing to iOS7. Today I faced the issue myself and found this article (it's been referenced from multiple other questions but it completes my earlier answer). Hope it helps!
Location permission issue iOS 11 and iOS 10
I figured out the issue by creating a quick stand alone app that only asked for permissions, I was given an error log that stated the keys I was using were wrong.
I had NSLocationAlwaysAndWhenInUsageDescription
instead of NSLocationAlwaysAndWhenInUseUsageDescription
which is odd because from the docs it states that NSLocationAlwaysAndWhenInUsageDescription
should be used. Switching to include the correct key fixed issue and now permissions works as expected for iOS 11 and 10.
Thanks for all the help.
iOS 11 Location Permission in
For iOS 11, there's a new key NSLocationAlwaysAndWhenInUseUsageDescription
. Add this key to Info.plist
.
Location Access Request in iOS 11
It is not optional anymore.
Since iOS 11 has been released, if your application requests the location to be always on (locationManager.requestAlwaysAuthorization()
), the users will automatically be given all three options.
Unlike in previous iOS versions, all options have to be displayed to the user. That leads to: you have to add a key for both options.
Adapted from Apple's Article - Requesting Always Authorization:
You are required to include the
NSLocationWhenInUseUsageDescription
andNSLocationAlwaysAndWhenInUseUsageDescription
keys in your app's
Info.plist file. (If your app supports iOS 10 and earlier, the
NSLocationAlwaysUsageDescription
key is also required.) If those keys
are not present, authorization requests fail immediately.
Reference: What's New in Location Technologies Video Session.
My CoreLocation based Swift app is not asking user's permission to access location
Move LocationManager.requestAlwaysAuthorization()
to the viewDidAppear
method.
EDIT:
Ok, you are asking requestAlwaysAuthorization
but in info.plist you set the When in usage...
key entry, so change the requestAlwaysAuthorization
to the requestWhenInUseAuthorization
App not asking for permission to access location, popup stays in background
The problem is that it can take a while for you to get authorized by LocationManager after you make the request. Therefore, on your first try you don't have authorization before reaching the closure after your request. I've addressed this by testing for authorization and, if I don't have it, putting in the request and then waiting for the callback to didChangeAuthorizationStatus before starting location updates. If I already do have authorization, I immediately start location updates.
By the second time you run the app, you have the authorization so the delay doesn't occur and you're OK to go.
To try this approach, include this section in your ViewDidLoad (I'm assuming that you don't need to run this whenever your view appears, but only when it first starts):
if CLLocationManager.authorizationStatus() != .authorizedAlways // Check authorization for location tracking
{
locationManager.requestAlwaysAuthorization() // LocationManager will callbackdidChange... once user responds
} else {
locationManager.startUpdatingLocation()
}
And add this delegate function to your class to be called by LocationManager once you're authorized:
// If we've been authorized to use location, start the processes, otherwise abort the operation
// since we can't proceed without locations
@nonobjc func locationManager(manager: CLLocationManager!, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
switch status
{
case .authorizedAlways:
locationManager.startUpdatingLocation()
default:
// User denied access, handle as appropriate
}
}
Here's the code I use to instantiate / configure the locationManager:
lazy var locationManager: CLLocationManager = {
[unowned self] in
var _locationManager = CLLocationManager()
_locationManager.delegate = self
_locationManager.desiredAccuracy = [a user setting in my app]
_locationManager.allowsBackgroundLocationUpdates = true
_locationManager.pausesLocationUpdatesAutomatically = false // So doesn't shut off if user stops to rest
_locationManager.activityType = .fitness
_locationManager.distanceFilter = Double([a user setting in my app])
return _locationManager
}()
This has been working for me so hopefully it will help.
Related Topics
Increment Uislider by 1 in Range 1 to 100
Pod Install Command with Error
How to Load Icarousel View from Storyboard or Xib
Uibutton Remove All Target-Actions
Completion Block for Popviewcontroller
How to Decode Aac Audio Buffer to Pcm Buffer in iOS
Best Way to Use Background Location Updates in iOS (Swift)
Strange Constraints Behaviour on iPad
iOS Launch Screen in React Native
Memory Leaks in the Swift Playground/Deinit{} Not Called Consistently
Accessing Core Data Stack in Mvvm Application
Use Different Googleservice-Info.Plist for Different Build Schemes
Uitextfield Leftview/Rightview Padding on iOS7
How to Crop Image Inside the Circle in Uiimageview in iOS