Solution: Location Services Not Working In iOS 8 Xcode 6

October 1, 2014October 1, 2014

I am working on a App since past few months which uses location data. Things were working fine earlier. But after updating to the Xcode 6 and using the new iOS 8 simulator, I observed the location services have stopped working. After a bit of research I find the solution. If you are facing similar issue. Here is the fix for you –

Unlike iOS 7 where it automatically asks the user for permission to use location data, In iOS 8 we need to call a specific method before calling the startUpdatingLocation.

Which method to call depends upon whether you want to use location service only in foreground, i.e. while the app is running, or in the background as well, i.e. which is app is in background.

For the prior, we need to call – requestWhenInUseAuthorization
and for the later, we need to call – requestAlwaysAuthorization

Note:

These are iOS 8 specific methods. If your app supports iOS 7 or below, you also need to add the following code with the method call –

123

//Put the required method name inside the @selector.if([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]){}

Note: You need to put this code before startUpdatingLocation method call.

Now we need to do one final thing, which is a requirement. We need to add a key to the Info.plist file. Depending on the method we are using above, the two keys are – NSLocationAlwaysUsageDescription and NSLocationWhenInUseUsageDescription.

These are string keys, where you will put the description or the message, which will appear while the system asks the user for location permission.