我正在尝试使用以下代码在viewDidLoad方法中获取当前位置:
//init the location manager
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
我有我的委托方法:
//if it fails to get the location
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
NSLog(@"didFailWithError: %@", error);
UIAlertView *errorAlert = [[UIAlertView alloc]
initWithTitle:@"Error" message:@"Failed to Get Your Location" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[errorAlert show];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
NSLog(@"didUpdateToLocation: %@", newLocation);
self.currentLocation = newLocation;
}
我的UIViewController符合CLLocationManagerDelegate,但是我没有任何活动,没有NSLog或错误。我已经在设备上进行了测试。有人可以给我指点一下这里可能出什么问题吗?
确保您遵循文档中的准则
特别是“ UIRequiredDeviceCapabilities”键在您的Info.plist中。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句