找不到 CLLocationManager startUpdatingLocation
Posted
技术标签:
【中文标题】找不到 CLLocationManager startUpdatingLocation【英文标题】:CLLocationManager startUpdatingLocation not found 【发布时间】:2012-12-12 22:11:15 【问题描述】:我一直在尝试向我的应用程序添加一项功能以获取位置并将变量放入 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
【问题讨论】:
【参考方案1】:请找到您的代码的更正。它应该工作。之后,您的代码应该实现 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
【讨论】:
以上是关于找不到 CLLocationManager startUpdatingLocation的主要内容,如果未能解决你的问题,请参考以下文章
如何判断 CLLocationManager 是不是正在主动扫描信标?
语义问题:找不到属性“regionMonitoringAvailable”
将经度和纬度从 CLLocationManager 传递到 URL?