ios4 - 找不到 CLLocationManager startUpdatingLocation

标签 ios4 core-location cllocationmanager

我一直在尝试向我的应用程序添加一项功能来获取位置并将变量放入 mysql 数据库中。我添加了 CoreLocation.framework 并导入 <CoreLocation/CoreLocation.h>在标题中。我尝试过不同的代码,但总是遇到类似的错误,例如下面评论的错误。是否有可能框架没有正确链接?

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:   (NSDictionary *)launchOptions                              
{ 
 CLLocationManager = self; // Expected identifier or '('
 [self startUpdatingLocation:nil]; // instance method '-startUpdatingLocation' not found
}



-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{
 CLLocationManager *locationManager = [[CLLocationManager alloc] release];
//initializing 'CLLocationManager *' with an expression of incompatible type 'void'
[locationManager startUpdatingLocation:nil];
//do stuff with the coordinates
}



@end

最佳答案

请查找您的代码的更正之处。它应该有效。之后,您的代码应该实现 CLLocationManagerDelegate 方法来获取位置信息。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:   (NSDictionary *)launchOptions                              
{ 
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
 locationManager.delegate = self;
[locationManager startUpdatingLocation:nil];}



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

 CLLocationManager *locationManager = [[CLLocationManager alloc] init];
 locationManager.delegate = self;
[locationManager startUpdatingLocation:nil];

//do stuff with the coordinates
}

关于ios4 - 找不到 CLLocationManager startUpdatingLocation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13849566/

相关文章:

iphone - iOS 中的加密用法

ios - 如何使用CLLocationManager-Swift获取当前经纬度

ios - 为什么在我允许后没有使用定位服务?

iphone - iOS CoreLocation 检查 CLLocation 时间戳以使用它

ios - 从浮点 lat long 创建的 CLLocation 显示出更高的精度

iphone - 在 Facebook 上共享链接,无需创建 Facebook 应用程序

iphone - iOS4.0 iphone应用程序在后台运行时AudioQueueStart失败

iphone - 如何对海拔执行 if else 语句

ios - CLCircularRegion 和唤醒应用

ios - 是否可以构建和发布使用更新 API 的 iOS 应用程序?