0

I am having a lot of trouble after updating to iOS 8. The following code worked before I updated to iOS and Xcode 6. Code is written inside viewDidLoad:

self.locationManager.delegate = self;
[self.locationManager requestWhenInUseAuthorization];
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[self.locationManager startUpdatingLocation];

In my .h file, I have locationManager as a property, also declaring CLLocationManagerDelegate:

@property CLLocationManager *locationManager;

I've set a breakpoint inside

-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations

but the code never ran.

What step am I missing???

EDIT: do note that the prompt asking the user to allow location services never appeared. I suspect that this is the issue but I did request the service right after I declared the delegate to self.

Also added

<key>NSLocationWhenInUseUsageDescription</key>
<string>Your message goes here</string>

But still does not work for me

Eric Chuang
  • 1,017
  • 9
  • 28
  • possible duplicate of [iOS 8 : Location Services not working](http://stackoverflow.com/questions/24062509/ios-8-location-services-not-working) – The dude Oct 09 '14 at 14:10

4 Answers4

1

if you start location before user agree to use location server

ios8 or later change to

- (xx)xxxx
{
   self.locationManager.delegate = self;
   self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;   
   if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedAlways) {
       [self.locationManager startUpdatingLocation];
   }else{
      [self.locationManager requestWhenInUseAuthorization];
   }     
}

- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
{ 
   if([CLLocationManager authorizationStatus] != kCLAuthorizationStatusNotDetermined){
      [self.locationManager startUpdatingLocation];
   }
}
ibcker
  • 504
  • 6
  • 11
0

You need to add NSLocationWhenInUseUsageDescription key to your info.plist. (From my testing, it can be an empty string, but the key must exist. Not sure if Apple fails review for empty string, though.)

Ian MacDonald
  • 13,472
  • 2
  • 30
  • 51
0

You need to use 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.

More information in this post: Location Services not working in iOS 8

Community
  • 1
  • 1
Sandro Machado
  • 9,921
  • 4
  • 36
  • 57
0

So after all the "iOS 8" issues, I realized my problem was that I didn't allocate and init my locationManager

self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
[self.locationManager requestWhenInUseAuthorization];
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;

    if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedAlways) {
        [self.locationManager startUpdatingLocation];
    }else{
        [self.locationManager requestWhenInUseAuthorization];
        [self.locationManager requestAlwaysAuthorization];
    }
[self.locationManager startUpdatingLocation];
Eric Chuang
  • 1,017
  • 9
  • 28