如何从 UIApplication openURL 检测 return
How to detect return from UIApplication openURL
我正在使用 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];
打开设置->隐私->位置服务没问题。
当用户打开 LocationService 并点击 "return to myApp" 时,如何从 myApp 中的“设置”中检测到重新调到 myApp?
我需要检测,因为我需要检查用户是否打开了 LocationService,如果是,我应该尝试 [locManager requestWhenInUseAuthorization];
。
我的主要问题是“如何检测从 [[UIApplication sharedApplication] openURL:url];
打开的应用程序返回到 myApp。
非常感谢您的帮助。
您无法明确检测到用户有 "returned from the app I opened"。您可以检测到您的应用已激活,但您无法知道 为什么 或用户在此期间正在做什么。但你不需要。
如果您只是想知道用户是关闭还是打开了位置服务,或者以其他方式更改了您的授权,只需实施 CLLocationManagerDelegate 方法 locationManager:didChangeAuthorizationStatus:
。如果用户在应用程序暂停时进行了更改,您将在应用程序再次激活后立即被呼叫。您应该无论如何使用此方法作为授权请求结构的一部分。
我正在使用 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];
打开设置->隐私->位置服务没问题。
当用户打开 LocationService 并点击 "return to myApp" 时,如何从 myApp 中的“设置”中检测到重新调到 myApp?
我需要检测,因为我需要检查用户是否打开了 LocationService,如果是,我应该尝试 [locManager requestWhenInUseAuthorization];
。
我的主要问题是“如何检测从 [[UIApplication sharedApplication] openURL:url];
打开的应用程序返回到 myApp。
非常感谢您的帮助。
您无法明确检测到用户有 "returned from the app I opened"。您可以检测到您的应用已激活,但您无法知道 为什么 或用户在此期间正在做什么。但你不需要。
如果您只是想知道用户是关闭还是打开了位置服务,或者以其他方式更改了您的授权,只需实施 CLLocationManagerDelegate 方法 locationManager:didChangeAuthorizationStatus:
。如果用户在应用程序暂停时进行了更改,您将在应用程序再次激活后立即被呼叫。您应该无论如何使用此方法作为授权请求结构的一部分。