2010-08-16 122 views
3

我使用iPhone SDK 4.0.I已经使用下面的代码采取现在的位置,但它的委托方法是不是叫自动...我的代码如下:为什么在iOS4.0中不调用委托CurrentLotion的方法(CLLocationManager)?

在.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]; 

,但我不明白的是,当前的位置......我的委托方法是不叫:

  • (无效)的LocationManager (CLLocationManager *)经理 didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
+1

尝试安装到iphone上,因为代码看起来没问题。 – mrugen 2011-06-22 05:58:24

回答

0

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

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

这人会在什么情况下被称为出错。例如,位置管理器无法定位您的iPhone。

0

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

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

相关问题