iOS 8 中的 CLlocationManager 问题
Posted
技术标签:
【中文标题】iOS 8 中的 CLlocationManager 问题【英文标题】:Issue with CLlocationManager in iOS 8 【发布时间】:2015-03-18 11:43:05 【问题描述】:当我使用此代码配置 CLlocationManager 时:
- (void)viewDidLoad
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
self.locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters;
if([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)])
[self.locationManager requestAlwaysAuthorization];
// Or [self.locationManager requestWhenInUseAuthorization];
[self.locationManager startUpdatingLocation];
并设置位置委托
#pragma mark - CLLocationManagerDelegate
- (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);
CLLocation *currentLocation = newLocation;
if (currentLocation != nil)
self.textLongitude.text = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.longitude];
self.textLatitude.text = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.latitude];
不要发送已授权的警报,但 Info.plist 是完整的
当进入设置并更改设置 -> 隐私 -> 本地化并更改“始终”的状态,然后重新启动应用程序时,此状态是干净的。
【问题讨论】:
【参考方案1】:NSLocationAlwaysUsageDescription
在 plist 中拼写错误。
【讨论】:
非常非常非常感谢以上是关于iOS 8 中的 CLlocationManager 问题的主要内容,如果未能解决你的问题,请参考以下文章
Swift - iOS 8 中的 UIPopoverController