【问题标题】:why Delegate Methods for CurrentLotion(CLLocationManager) is not called in iOS4.0?为什么在 iOS4.0 中没有调用 CurrentLotion(CLLocationManager) 的委托方法?
【发布时间】:2011-03-30 07:26:22
【问题描述】:

我正在使用 iPhone sdk 4.0。我已使用以下代码获取当前位置,但它的委托方法未自动调用...我的代码如下:

.hfile

我有进口

CoreLocation/CoreLocation.h

也委托

CLLocationManagerDelegate

CLLocationManager *locationManager;

.mfile

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

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

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

}

【问题讨论】:

  • 尝试安装到 iphone 上,因为代码看起来没问题。

标签: iphone cllocationmanager


【解决方案1】:

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

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

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

【讨论】:

    【解决方案2】:

    我遇到同样的问题。所有代码看起来都不错,但没有调用委托方法。

    我完全关闭了模拟器。当我重新运行应用程序时,委托方法被调用。

    【讨论】:

      猜你喜欢
      • 2013-12-03
      • 2011-04-13
      • 1970-01-01
      • 2011-03-04
      • 2011-11-18
      • 1970-01-01
      • 1970-01-01
      • 2011-03-12
      • 1970-01-01
      相关资源
      最近更新 更多