【问题标题】:CLLocationManager is not working in the iOS 4.3 simulatorCLLocationManager 在 iOS 4.3 模拟器中不起作用
【发布时间】:2012-08-12 20:04:42
【问题描述】:

我正在使用 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 之前的真实设备中可能会出现问题。为什么它不起作用?

【问题讨论】:

  • 您能描述一下您所说的“不工作”是什么意思吗?委托方法根本没有被调用吗?也许尝试设置desiredAccuracy过滤器。检查授权状态。实现 didFail 方法,看看它是否落入那里
  • 确保在尝试使用CCLocationManager之前检查[CLLocationManager locationServicesEnabled],您的定位服务可能会被关闭,即使在模拟器中也是如此。
  • 我试过“locationServicesEnabled”方法,你是对的乔,位置服务没有启用。那么我该如何启用它或者我应该怎么做?
  • 您需要进入模拟器中的设置。从那里你应该能够打开定位服务。
  • 我明白为什么。 ios 模拟器 4.3 不支持定位服务,但我认为我的代码可以在真实设备上运行。

标签: iphone objective-c ios ios4 cllocationmanager


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-23
    • 2012-09-23
    • 2013-03-11
    • 1970-01-01
    • 2011-12-08
    • 1970-01-01
    相关资源
    最近更新 更多