Laxy
Laxy

Reputation: 149

iOS 8 CLLocationManagerDelegate methods are never called

//View did Load Method- LocationManager is allocated and have included the CLLocationManagerDelegate in .h File

-ViewDidLoad{
self.locationManager = [[CLLocationManager alloc] init];
    self.locationManager.delegate = self;
    self.locationManager.desiredAccuracy=kCLLocationAccuracyBest;
    self.locationManager.distanceFilter=kCLDistanceFilterNone;
    [self.locationManager requestWhenInUseAuthorization];
    [self.locationManager startMonitoringSignificantLocationChanges];
    [self.locationManager startUpdatingLocation];

}
// Location Manager Delegate Methods
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
    NSLog(@"%@", [locations lastObject]);
}

Upvotes: 1

Views: 170

Answers (1)

Rajan Maheshwari
Rajan Maheshwari

Reputation: 14571

In plist you have to add 2 entries

  1. NSLocationWhenInUseUsageDescription
  2. NSLocationAlwaysUsageDescription

Make the string of both as "Location is required to find out where you are" or anything

self.locationManager = [[CLLocationManager alloc]init];

if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
    [self.locationManager requestWhenInUseAuthorization];
}
self.locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;
CLAuthorizationStatus authorizationStatus= [CLLocationManager authorizationStatus];

if (authorizationStatus == kCLAuthorizationStatusAuthorized ||
    authorizationStatus == kCLAuthorizationStatusAuthorizedAlways ||
    authorizationStatus == kCLAuthorizationStatusAuthorizedWhenInUse) {
    NSLog(@"You are authorized");

}

self.locationManager.delegate = self;
[self.locationManager startUpdatingLocation];

Hope this helps

Upvotes: 3

Related Questions