2013-03-25 2 views
0

Я работаю над приложением Mac. Ниже приведен свернутый тестовый пример. Кажется, что CLLocationManager не вызывает никаких методов делегата. Вы видите что-то не так?CLLocationManager не вызывающий делегат

#import <Foundation/Foundation.h> 
#import <CoreLocation/CoreLocation.h> 

@interface Delegate : NSObject <CLLocationManagerDelegate> 
@property (strong, nonatomic) CLLocationManager *locationManager; 
@property (nonatomic) BOOL once; 
@end 

@implementation Delegate; 
@synthesize locationManager = _locationManager; 
@synthesize once = _once; 

- (void)start:(BOOL)once 
{ 
    self.once = once; 
    self.locationManager = [[CLLocationManager alloc] init]; 
    self.locationManager.desiredAccuracy = kCLLocationAccuracyBest; 
    self.locationManager.delegate = self; 
    [self.locationManager startUpdatingLocation]; 
    NSLog(@"Location: %@", self.locationManager.location); 
    NSLog(@"authorizationStatus: %d", [CLLocationManager authorizationStatus]); 
    NSLog(@"locationServicesEnabled: %d", [CLLocationManager locationServicesEnabled]); 
    NSLog(@"significantLocationChangeMonitoringAvailable: %d", [CLLocationManager significantLocationChangeMonitoringAvailable]); 
    NSLog(@"headingAvailable: %d", [CLLocationManager headingAvailable]); 
    NSLog(@"regionMonitoringAvailable: %d", [CLLocationManager regionMonitoringAvailable]); 
} 

- (void)locationManager:(CLLocationManager *)manager 
    didUpdateToLocation:(CLLocation *)newLocation 
      fromLocation:(CLLocation *)oldLocation; 
{ 
    printf ("%s\n", [newLocation.description UTF8String]); 
    if (self.once) exit(0); 
} 

- (void)locationManager:(CLLocationManager *)manager 
     didFailWithError:(NSError *)error 
{ 
    printf ("ERROR: %s\n", [[error localizedDescription] UTF8String]); 
    exit(1); 
} 
@end 

int main(int argc, const char * argv[]) 
{ 
    @autoreleasepool { 
     BOOL once = (argc > 1 && strcmp(argv[1], "--once") == 0); 
     Delegate *delegate = [[Delegate alloc] init]; 
     [delegate performSelectorOnMainThread:@selector(start:) withObject:[NSNumber numberWithBool:once] waitUntilDone:NO]; 
     NSRunLoop *runLoop = [NSRunLoop mainRunLoop]; 
     [runLoop run]; 
    } 
    return 0; 
} 

Теперь выход:

2013-03-25 20:24:28.342 CoreLocationCLI[75031:303] Location: (null) 
2013-03-25 20:24:28.344 CoreLocationCLI[75031:303] authorizationStatus: 0 
2013-03-25 20:24:28.345 CoreLocationCLI[75031:303] locationServicesEnabled: 1 
2013-03-25 20:24:28.345 CoreLocationCLI[75031:303] significantLocationChangeMonitoringAvailable: 0 
2013-03-25 20:24:28.346 CoreLocationCLI[75031:303] headingAvailable: 0 
2013-03-25 20:24:28.346 CoreLocationCLI[75031:303] regionMonitoringAvailable: 1 

Update: теперь это реализовано и работает. Реализация для печати на местах по адресу https://github.com/fulldecent/corelocationcli

+0

ли ваши устройства/машины поддержки Location Services? Включено ли это? Имеет ли приложение разрешение на устройство? – Tim

+0

Как насчет 'NSLog (@"% @ ", self.locationManager.location)' и различных свойств CLLocation? –

+0

Поддерживается, я добавил регистрацию, чтобы показать –

ответ

0

Перед тем как позвонить startUpdatingLocation отметьте для + (BOOL)locationServicesEnabled значение.

Если оно выключено, укажите местоположение, указанное в настройках вашей системы.

+0

Включены. Я обновил вопрос для регистрации и показа этого. –

0

authorizationStatus: 0

Это просто означает, что у вас есть разрешение ВЫКЛЮЧЕН. PLease убедитесь, что он включен. - (Недействительными) locationManager: (CLLocationManager *) менеджер didChangeAuthorizationStatus: (CLAuthorizationStatus) Статус

0

Помещенные kCLAuthorizationStatusAuthorizedAlways ИЛИ kCLAuthorizationStatusAuthorizedWhenInUse свойства в info.plist

Смежные вопросы