2

我一直在尝试向我的应用程序添加一个功能来获取位置并将变量放入 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
4

1 回答 1

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
}
于 2012-12-13T07:10:23.467 回答