0

I am trying to get the current location using this code in my viewDidLoad method:

//init the location manager
locationManager = [[CLLocationManager alloc] init];    
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;

[locationManager startUpdatingLocation];

and I have my delegate methods:

//if it fails to get the location
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
    NSLog(@"didFailWithError: %@", error);
    UIAlertView *errorAlert = [[UIAlertView alloc]
                               initWithTitle:@"Error" message:@"Failed to Get Your Location" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [errorAlert show];
}


- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    NSLog(@"didUpdateToLocation: %@", newLocation);
    self.currentLocation = newLocation;

}

my UIViewController conforms to the CLLocationManagerDelegate however I am getting no activity, no NSLog or errors. I have tested on a device. Could someone give me a pointer to what might be going wrong here please?

Kex
  • 8,023
  • 9
  • 56
  • 129
  • Did you activate LocationTracking in your Project? Did the device ask if you allow location tracking? Check your system settings, if the app is registered for locations – Christian Mar 15 '15 at 11:40
  • The device has never asked me this no. Doesn't seem to be registered for locations either. I wonder if it's because I'm using iOS 8 – Kex Mar 15 '15 at 11:43
  • Check my answer here, Its a commonly asked question w.r.t. iOS 8 & location manager. http://stackoverflow.com/questions/26777246/using-freeway-drive-city-run-in-ios-simulator-in-background-mode?answertab=active#tab-top – Amit Mar 15 '15 at 11:48

1 Answers1

1

make sure, you follow the guidelines in the Documentation

https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/LocationAwarenessPG/CoreLocation/CoreLocation.html

especially that the ´UIRequiredDeviceCapabilities´ key is in your Info.plist.

Christian
  • 4,596
  • 1
  • 26
  • 33
  • thanks for this, works now. It's backwards compatible with iOS versions below 8? – Kex Mar 15 '15 at 12:21