简体   繁体   English

CLLocationManager不调用didUpdateLocations

[英]CLLocationManager not calling didUpdateLocations

I've been unable to figure out why location manager isn't providing updates to me. 我一直无法弄清楚为什么位置管理器不向我提供更新。 I've added the key, tested on simulator and on a device. 我添加了密钥,该密钥已在模拟器和设备上进行了测试。

Edit: STDOUT also contains "Delegate: " 编辑: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 FirstViewController.h

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

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

FirstViewController.cpp 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

Perhaps it's just the result of a typo. 也许这只是拼写错误的结果。

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

should be 应该

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

You forgot the "r" at the end of "locationManager". 您忘记了“ locationManager”末尾的“ r”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 CLLocationManager startUpdatingLocation不调用locationManager:didUpdateLocations:或locationManager:didFailWithError: - CLLocationManager startUpdatingLocation not calling locationManager:didUpdateLocations: or locationManager:didFailWithError: CLLocationManager requestLocation没有调用didUpdateLocations - CLLocationManager requestLocation isn't calling didUpdateLocations 自定义CLLocationManager didUpdateLocations函数 - Custom CLLocationManager didUpdateLocations Function CLLocationManager didUpdateLocations未被调用 - CLLocationManager didUpdateLocations not being called CLLocationManager didUpdateLocations或didUpdateToLocation - CLLocationManager didUpdateLocations or didUpdateToLocation 在ios中实现了doUpdateLocations委托CLLocationManager的方法 - implement didUpdateLocations delegate method of CLLocationManager in ios CLLocationManager不会向didUpdateLocations方法发送位置 - CLLocationManager does not send location to the didUpdateLocations method 如何在函数中返回CLLocationManager didUpdateLocations的值? - How to return the value of CLLocationManager didUpdateLocations in function? CLLocationManager didUpdateLocations没有通过plist条目被称为iOS 8 - CLLocationManager didUpdateLocations not being called iOS 8 with plist entries CLLocationManager的dispatch_after didUpdateLocations或didFailWithError - dispatch_after CLLocationManager didUpdateLocations or didFailWithError
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM