繁体   English   中英

我的应用程序在iphone中打开/关闭GPS位置

[英]GPS location is on/off in iphone for my app

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

BOOL servicesEnabled = [CLLocationManager locationServicesEnabled];

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

使用您的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.)"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM