如何使我的ios应用程序出现在设置中的位置服务中

时间:2012-06-17 04:59:15

标签: ios ios5 cllocationmanager

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

2 个答案:

答案 0 :(得分:2)

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

尝试调用这样的东西:

[self.locationManager startUpdatingLocation];

那应该这样做

答案 1 :(得分: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];
    }
}