0

我检查GPS位置是on/off使用此代码

BOOL servicesEnabled = [CLLocationManager locationServicesEnabled];

在 iphone 中打开/关闭 LocationServices 时它可以正常工作,但是我为我的应用程序设置了 LocationServices 它只返回servicesEnabledYES那个时候[CLLocationManager locationServicesEnabled] 如何签locationServicesEnabled入我的应用程序 例如:我禁用了我的应用程序位置服务,如 instagram,如何解决这个问题LocationServices在 iphone 或 ipad 中 检查特定应用程序的问题?在此处输入图像描述

4

1 回答 1

2

使用您的CLLocationManagerDelegate's locationManager: didFailWithError:方法并检查kCLErrorDenied错误以查看用户是否拒绝位置服务。

- (void)viewDidLoad
{
    locationManager = [[CLLocationManager alloc] init];

    locationManager.delegate = self;

    locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;

    // Set a movement threshold for new events.

    locationManager.distanceFilter = 500;

    [locationManager startUpdatingLocation];
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)locationManager:(CLLocationManager *)manager

     didUpdateLocations:(NSArray *)locations {

    // If it's a relatively recent event, turn off updates to save power

}

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{

    NSLog(@"%@",error);
}

如果您的应用程序禁用了位置服务,那么它会给您错误

Error Domain=kCLErrorDomain Code=1 "The operation couldn’t be completed. (kCLErrorDomain error 1.)"
于 2013-03-25T06:36:29.773 回答