当前位置: 动力学知识库 > 问答 > 编程问答 >

ios - How to detect return from UIApplication openURL

问题描述:

I'm creating an app using CoreLocation.

Usually, everyone check if CLAuthorizationStatus.

But I wonder if the user disabled LocationService itself on iOS device's Setting, what will happen. And I found that in such case, CLAuthorizationStatus is set to kCLAuthorizationStatusDenied.

So, I think to check the status of Setting, and if location service is disabled, open iOS's Setting like below.

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];

It worked fine to open Setting->Privacy->LocationService.

When user turned on LocationService and tap on "return to myApp", how can I detect retuning to myApp from Setting in myApp?

I need to detect as I need to check if user turned on LocationService or not, and if yes, I should try [locManager requestWhenInUseAuthorization];.

My main question is that "How to detect returning to myApp from the app I opened by [[UIApplication sharedApplication] openURL:url];.

Thank you so much for your kind helps.

网友答案:

You cannot specifically detect that the user has "returned from the app I opened". You can detect that your app has become active, but you cannot know why or what the user was doing in the meantime. But you don't need to.

If you simply want to know whether the user turned location services off or on, or otherwise altered your authorization, simply implement the CLLocationManagerDelegate method locationManager:didChangeAuthorizationStatus:. If the user made a change while the app was suspended, you'll be called as soon as the app is activated again. You should be using this method anyway as part of your authorization request structure.

分享给朋友:
您可能感兴趣的文章:
随机阅读: