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