iOS 8 CLLocationManagerDelegate methods are never called

ぃ、小莉子 提交于 2019-12-11 12:03:21

问题


//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]);
}

回答1:


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



来源:https://stackoverflow.com/questions/28837146/ios-8-cllocationmanagerdelegate-methods-are-never-called

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!