2014-11-29 2 views
0

Мне не удалось выяснить, почему менеджер местоположений не предоставляет мне обновления. Я добавил ключ, протестированный на симуляторе и на устройстве.CLLocationManager не вызывает didUpdateLocations

Edit: STDOUT также содержит "делегат:"

STDOUT

2014-11-28 22:18:30.066 Speedo[14091:150298] Status: 4 
2014-11-28 22:18:30.069 Speedo[14091:150298] Is when in use? 1 
2014-11-28 22:18:30.158 Speedo[14091:150298] New status: 4 
2014-11-28 22:18:30.159 Speedo[14091:150298] Is when in use? 1 

FirstViewController.h

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

@interface FirstViewController : UIViewController <CLLocationManagerDelegate> 
@property (weak, nonatomic) IBOutlet UILabel* speedLabel; 
@end 

FirstViewController.cpp

#import "FirstViewController.h" 
#import <CoreLocation/CoreLocation.h> 

@interface FirstViewController() 

@end 

@implementation FirstViewController { 
    CLLocationManager *locationManager; 
} 


- (void)viewDidLoad { 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 

    locationManager = [[CLLocationManager alloc] init]; 
    locationManager.delegate = self; 
    self.speedLabel.text = @""; 

    if([locationManager respondsToSelector: @selector(requestWhenInUseAuthorization)]) { 
     [locationManager requestWhenInUseAuthorization]; 
    } 

    // locationManager.desiredAccuracy = kCLLocationAccuracyBest; 
    // locationManager.distanceFilter = 0.01; 
    [locationManager startUpdatingLocation]; 

    NSLog(@"Delegate: %@", locationManager.delegate); 
    NSLog(@"Status: %d", [CLLocationManager authorizationStatus]); 
    NSLog(@"Is when in use? %d", [CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedWhenInUse); 
} 

- (void)didReceiveMemoryWarning { 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

#pragma mark - CLLocationManagerDelegate 

- (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 didChangeAuthorizationStatus:(CLAuthorizationStatus)status { 
    NSLog(@"New status: %d", status); 
    NSLog(@"Is when in use? %d", [CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedWhenInUse); 
    [manager startUpdatingLocation]; 
} 

-(void)locationManage: (CLLocationManager *)manager didUpdateLocations:(NSArray*)locations { 
    CLLocation* last = [locations lastObject]; 
    NSLog(@"Speed: %f m/s", last.speed); // meter per second 
    // TODO: support mutli-units 
    // m/s -> mph 
    // 1 -> 2.236 
    self.speedLabel.text = [NSString stringWithFormat:@"%d", (int)(last.speed * 2.23694)]; 
} 

@end 
+0

Для чего это стоит, я использую подписку adhoc на Pangu 8.1 и синхронизацию приложений AngelXWing. –

ответ

2

Возможно, это результат опечатки.

-(void)locationManage: (CLLocationManager *)manager didUpdateLocations:(NSArray*)locations { 

должен быть

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

Вы забыли "г" в конце "locationManager".

+0

Спасибо, именовать метод правильно делает трюк! –

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