CLLocationManager在iOS 4.3模拟器中无法工作。

3
我正在使用CLLocationManager来确定我的当前位置:
- (void)viewDidLoad
{
    locationManager = [[CLLocationManager alloc] init];
    [locationManager setDelegate:self];
    [locationManager startUpdatingLocation];
}

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation 
{
    self.currentLocation = newLocation;
    NSTimeInterval locationAge = -[newLocation.timestamp timeIntervalSinceNow];
    if (locationAge > 5.0) return;
    if (newLocation.horizontalAccuracy < 0) return;
    if (self.currentLocation == nil || self.currentLocation.horizontalAccuracy > newLocation.horizontalAccuracy) {
        self.currentLocation = newLocation;
    }
    [locationManager stopUpdatingLocation];
}

这段代码可以在iOS 5.1模拟器上正常运行,但在iOS 4.3模拟器上无法正常工作。我认为在iOS 5.1之前的真实设备上也可能会有问题。为什么它不能正常工作呢?


你能描述一下你所说的“不起作用”是什么意思吗?代理方法根本没有被调用吗?也许尝试设置所需的准确度过滤器。检查授权状态。实现didFail方法并查看它是否进入其中。 - Mike
1
在尝试使用CLLocationManager之前,请确保检查[CLLocationManager locationServicesEnabled],因为即使在模拟器中,您的位置服务也可能被关闭。 - Joe
我也遇到了同样的问题。你找到解决方案了吗? - Viral Narshana
尝试在iOS 6或iOS 5模拟器中运行相同的代码,并在评论中告诉我它是否可行... - user1832451
是的,它在iOS 5和iOS 6模拟器中正常工作。 - Viral Narshana
显示剩余3条评论
1个回答

0

iOS模拟器在iOS 5之前不支持模拟位置。你遇到的问题是模拟器的限制。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接