alu
alu

Reputation: 190

Cannot retrieve device location

I'm trying to get the device's latitude/longitude, and I've followed this tutorial exactly. http://ios-blog.co.uk/tutorials/getting-the-users-location-using-corelocation/

When I run the program the labels should update to the latitude and longitude (I set the simulator's location to "Apple" but the labels don't update at all. I also never get the prompt asking me to allow the app to use the device's location. I tried deleting the app from the simulator and running it again fresh, but that didn't change anything.

Anyone have any idea why this isn't working? I wonder if it's something to do with the latest version of Xcode (I'm using 6) not working with the tutorial that worked for a previous version. Thoughts?

Upvotes: 0

Views: 61

Answers (2)

Peter Heide
Peter Heide

Reputation: 519

If you are building for iOS 8, did you ask for authorization before starting CLLocationManager, as described here?: Xcode 6/iOS 8 Location Simulation doesn't work

Essentially, calling one of these methods:

[self.locationManager requestWhenInUseAuthorization];  // For foreground access
[self.locationManager requestAlwaysAuthorization]; // For background access

Upvotes: 0

Ian MacDonald
Ian MacDonald

Reputation: 14030

You need to add a NSLocationWhenInUseUsageDescription key to your info.plist.

You also need to call:

locationManager = [[CLLocationManager alloc] init];
[locationManager requestWhenInUseAuthorization];

Upvotes: 1

Related Questions