XCode iOS 8: Device / Simulator does not capture User Location

There is an added step required to allow the device to capture the user’s location either in the Simulator or in the iOS Device.

(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:

@import CoreLocation;

(2) In iOS 8, you must first call either:

// For use in background
requestAlwaysAuthorization (on the instance)

if([<CLLocationManager object> respondsToSelector:@selector(requestWhenInUseAuthorization)]){
[<CLLocationManager> requestWhenInUseAuthorization];
}
// For use in foreground
[<_MapView Object> setUserTrackingMode:MKUserTrackingModeFollowWithHeading animated:NO];

(3) Then, you must add a NSLocationAlwaysUsageDescription or 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.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s