gpt4 book ai didi

iphone - 为什么在iOS4.0中没有调用CurrentLotion(CLLocationManager)的委托(delegate)方法?

转载 作者:行者123 更新时间:2023-12-03 20:16:41 26 4
gpt4 key购买 nike

我正在使用 iPhone sdk 4.0。我使用下面的代码来获取当前位置,但它的委托(delegate)方法不会自动调用...我的代码如下:

.h文件

我有导入

CoreLocation/CoreLocation.h

也委托(delegate)

CLLocationManagerDelegate

CLLocationManager *locationManager;

.mfile

    locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; // 100 m
[locationManager startUpdatingLocation];

但我没有得到当前位置......我的委托(delegate)方法未被调用:

- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{

}

最佳答案

你的代码对我来说看起来是正确的。您是否也尝试过在真正的 iPhone 上运行此代码?模拟器并不总是响应位置管理器更新。您还应该将另一个重要的委托(delegate)方法添加到 .m 文件中:

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error

如果出现问题,将调用此函数。例如,位置管理器无法本地化您的 iPhone。

关于iphone - 为什么在iOS4.0中没有调用CurrentLotion(CLLocationManager)的委托(delegate)方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3491289/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com