我正在使用CoreLocation创建应用。
通常,每个人都会检查CLAuthorizationStatus。 但我想知道用户是否在iOS设备的设置上禁用了LocationService,会发生什么。我发现在这种情况下,CLAuthorizationStatus设置为kCLAuthorizationStatusDenied。
因此,我想检查设置的状态,如果禁用位置服务,请打开iOS的设置,如下所示。
if(![CLLocationManager locationServicesEnabled])
{
UIAlertController *alert = nil;
alert = [UIAlertController alertControllerWithTitle:nil
message:@"Please turn on Location Service on iOS's Setting."
preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"OK"
style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
NSURL *url = [NSURL URLWithString:@"prefs:root=LOCATION_SERVICES"];
[[UIApplication sharedApplication] openURL:url];
}]];
[self presentViewController:alert animated:YES completion:nil];
打开Setting-> Privacy-> LocationService。
工作正常当用户打开LocationService并点击"返回myApp"时,如何通过myApp中的设置检测到myApp的重新调整?
我需要检测是否需要检查用户是否启用了LocationService,如果是,我应该尝试[locManager requestWhenInUseAuthorization];
。
我的主要问题是"如何通过[[UIApplication sharedApplication] openURL:url];
打开的应用检测返回myApp。
非常感谢您的帮助。
答案 0 :(得分:0)
您无法专门检测到用户“已从我打开的应用中返回”。您可以检测到您的应用已变为活动状态,但在此期间您无法知道为什么或用户正在做什么。但你不需要。
如果您只是想知道用户是关闭还是打开了位置服务,或者是否更改了您的授权,只需实现CLLocationManagerDelegate方法locationManager:didChangeAuthorizationStatus:
即可。如果用户在暂停应用时进行了更改,则会在应用再次激活后立即呼叫您。您应该使用此方法无论如何作为授权请求结构的一部分。