CLLocationManager authorization issue iOS 8
It's an iOS 8 related issue. You have to put NSLocationAlwaysUsageDescription
or NSLocationWhenInUseUsageDescription
keys in your .plist
file (value may be an additional message that will be presented in location alert). These keys are required in iOS 8.
How it's said in Apple guidelines:
This key is required when you use the requestAlwaysAuthorization
method of the CLLocationManager class to request authorization for
location services. If this key is not present and you call the
requestAlwaysAuthorization method, the system ignores your request and
prevents your app from using location services.
Location Services not working in iOS 8
I ended up solving my own problem.
Apparently in iOS 8 SDK, requestAlwaysAuthorization
(for background location) or requestWhenInUseAuthorization
(location only when foreground) call on CLLocationManager
is needed before starting location updates.
There also needs to be NSLocationAlwaysUsageDescription
or NSLocationWhenInUseUsageDescription
key in Info.plist
with a message to be displayed in the prompt. Adding these solved my problem.
For more extensive information, have a look at: Core-Location-Manager-Changes-in-ios-8
CLLocationManager authorization message not show in ios iOS 8.0.1
In iOS8 you have to request the user to authorize the access by using requestWhenInUseAuthorization
or requestAlwaysAuthorization
.
And you have add either of the keys NSLocationWhenInUseUsageDescription
or NSLocationAlwaysUsageDescription
with proper messages to the info.plist
if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)])
{
[self.locationManager requestWhenInUseAuthorization];
}
CLLocationManager.authorizationStatus() always CLAuthorizationStatus.NotDetermined with swift&objC app
Keep in mind that NSLocationAlwaysUsageDescription
or NSLocationWhenInUseUsageDescription
keys are now mandatory, so you should include that in your plist.
prompting for location authorization in iOS8
The error message is quite self-explained.
First of all, you didn't initialized CLLocationManager
in your viewDidLoad
. You can initialize with (before the delegate
line):
self.locationManager = [[CLLocationManager alloc] init];
Then, you have to request for location service, using [self.locationManager requestWhenInUseAuthorization]
or [self.locationManager requestAlwaysAuthorization]
. (Not to forget to add corresponding usage description key in Info.plist
).
Last, you have to check the response of authorization from user. If user denied the authorization, you shouldn't start any Location Service-related actions, until you ask again.
Update if you support iOS 7 as well, the codes will be slightly different.
Related Topics
iOS Web App: Showing Content Only If the Application Is Standalone
Geofire Query on User Location
How to Encrypt and Decrypt a String(Plain Text) with Rsa Public Key in iOS, Swift
How to Overlay One Video on Another in iOS
Measuring Time Accurately in Swift for Comparison Across Devices
Rec iOS Conversations. Where to Start
Ios-8 and Later - Uitableview Inside an Uialertcontroller
How Is Filters Uiscrollview/Uicollectionview in Apple's Photos App Implemented That It Opens So Fast
How to Use Nsurlsession to Determine If Resource Has Changed
Making Phone Calls on the Iphone
Taking Screenshots in the Background (Ios) - Improving Performance
Allow "Auto Lock" While Video Is Being Played
How Can One Enable Keyboard Like in Imessages/Fb Messenger in Landscape Mode at iOS8
Grouping Coredata by Date() in Swiftui List as Sections