我一直在尝试为我的应用添加一个功能来获取位置并将变量放入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
答案 0 :(得分:2)
请查看代码的更正。它应该工作。之后,您的代码应实现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
}