NOTE: The implementation has evolved since this blog post, please check the most recent Apple docs and Stack Overflow for additional info if you are still having trouble. Here's a good place to start.
Using Core Location to get a user’s current GPS Location is a cornerstone feature of thousands of great apps. It’s incredibly useful to calculate a user’s distance from a point of interest or determine if they are nearby to other users. With the GPS from a modern iPhone, you can even use reverse geocoding to quickly determine a user’s current street address.
If you try to implement Core Location in iOS 8 using previous tried and tested methods, you’ll start running into trouble the moment you attempt to add a
<CLLocationManagerDelegate> to your code.
(1) After linking the Core Location framework in your Project Settings (near the bottom on the General tab), add this to the appropriate header file:
(2) In iOS 8, you must first call either:
// For use in background requestAlwaysAuthorization (on the instance)
// For use in foreground requestWhenInUseAuthorization (on the instance)
(3) Then, you must add a
NSLocationWhenInUseUsageDescription key to your project’s Info.plist containing the message to be displayed to the user at the prompt.
<key>NSLocationAlwaysUsageDescription</key> <string>Your message goes here</string>
<key>NSLocationWhenInUseUsageDescription</key> <string>Your message goes here</string>
The user will not be prompted unless one of these are added to the Info.plist.
Do you have thoughts or tips & tricks using Core Location with iOS 8?
Please leave a comment below!
Home Blog LinkedIn Contact Me