问题描述
我同时使用模拟器和设备进行测试,但是无论我做什么,从不调用didUpdateToLocation.我尝试在SIM卡中更改位置,然后关闭然后再打开手机上的位置服务,以强制手机搜索新位置...什么都没有.在我的viewDidLoad()中,我已经这样启动了CLLocationManager:
I am using both the simulator and my device to test this, but no matter what I do, didUpdateToLocation is never called. I have tried changing my location in the sim, turning off and then on again my location services on my phone to force the phone to search for a new location... nothing. In my viewDidLoad(), I have started the CLLocationManager as so:
CLLocationManager *manager = [[CLLocationManager alloc] init];
if (![CLLocationManager locationServicesEnabled])
{
UIAlertView *servicesDisabledAlert = [[UIAlertView alloc] initWithTitle:@"Location Services Disabled" message:@"You currently have all location services for this device disabled. If you proceed, you will be asked to confirm whether location services should be reenabled." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[servicesDisabledAlert show];
} else {
manager.desiredAccuracy = kCLLocationAccuracyBest;
manager.delegate = self;
[manager startUpdatingLocation];
}
在更新位置方法中,我有这个:
and in the update location method I have this:
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
NSLog(@"NEW LOCATION! Accuracy:[%f]",newLocation.horizontalAccuracy);
}
有人知道为什么不称呼它吗?
Does anyone have any ideas why this isn't being called?
推荐答案
您是否在头文件中添加了位置委托?
Did you add location delegate in your header file ?
这篇关于didUpdateToLocation从未调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!