1

我写了一个 CLLocationManager ios 应用程序。但是,我在 iPhone 的设置中看不到我的应用程序出现在定位服务中。我是否需要在 Xcode 的 ios 项目中的 plist 中设置特定值?提前致谢!

4

2 回答 2

2

一旦调用实际需要位置跟踪的代码,它应该会自动出现(每当弹出窗口第一次显示:你允许...)

尝试调用这样的东西:

[self.locationManager startUpdatingLocation];

那应该这样做

于 2012-06-17T05:41:42.690 回答
0

在 iOS -8 中需要做一些改动:

locationManager = [[CLLocationManager alloc] init];
    locationManager.delegate = self;
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    if([locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]){
        [locationManager requestWhenInUseAuthorization];
    }else{
        [locationManager startUpdatingLocation];
    }

需要在 plist 中添加 2 个带有空白值的额外键 1)NSLocationWhenInUseUsageDescription 2)NSLocationAlwaysUsageDescription

#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) {
        NSString *strLat = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.longitude];
        NSString *strLong = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.latitude];
    }
}
于 2015-05-29T06:20:45.400 回答