Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 为什么在iOS4.0中不调用CurrentLotion(CLLocationManager)的委托方法?_Iphone_Cllocationmanager - Fatal编程技术网

Iphone 为什么在iOS4.0中不调用CurrentLotion(CLLocationManager)的委托方法?

Iphone 为什么在iOS4.0中不调用CurrentLotion(CLLocationManager)的委托方法?,iphone,cllocationmanager,Iphone,Cllocationmanager,我使用的是iPhone sdk 4.0。我使用了以下代码获取当前位置,但不会自动调用其委托方法…我的代码如下所示: 在.hfile中 locationManager = [[CLLocationManager alloc] init]; locationManager.delegate = self; locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move locationManager.de

我使用的是iPhone sdk 4.0。我使用了以下代码获取当前位置,但不会自动调用其委托方法…我的代码如下所示:

.hfile中

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

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上运行此代码?模拟器并不总是对位置管理器更新做出响应。 还有一个重要的委托方法,您应该添加到.m文件中:

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error -(无效)locationManager:(CLLocationManager*)manager错误:(N错误*)错误
如果出现问题,将调用此函数。例如,位置管理器无法本地化您的iPhone

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


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

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