【问题标题】:Issue with CLlocationManager in iOS 8iOS 8 中的 CLlocationManager 问题
【发布时间】: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 是完整的

当进入设置并更改设置 -> 隐私 -> 本地化并更改“始终”的状态,然后重新启动应用程序时,此状态是干净的。

【问题讨论】:

    标签: objective-c cllocationmanager


    【解决方案1】:

    NSLocationAlwaysUsageDescription 在 plist 中拼写错误。

    【讨论】:

    • 非常非常非常感谢
    猜你喜欢
    • 2014-08-31
    • 2014-12-14
    • 1970-01-01
    • 2011-11-23
    • 1970-01-01
    • 1970-01-01
    • 2014-09-20
    • 1970-01-01
    • 2015-07-14
    相关资源
    最近更新 更多