lr100
lr100

Reputation: 600

Prompt for general iOS Location Services

I would like to ask the user to enable the general Locations Services (not the app specific Location Services) if as a whole they never get prompted to enable it for the app.

Is there a way to prompt the user to turn on Location Services as a whole every time they open the app and it is disabled?

Code found in other threads, but it is App specific, not general Location Services:

if(![CLLocationManager locationServicesEnabled]) {
    NSLog(@"Location Services is OFF GLOBALLY");

    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString( @"Location Services", @"" ) message:NSLocalizedString( @"Please Set Location Services to On and Restart App\n\nSettings->Privacy->Location Services", @"" ) preferredStyle:UIAlertControllerStyleAlert];

    UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString( @"OK", @"" ) style:UIAlertActionStyleDefault handler:nil];

    [alertController addAction:okAction];

    [self presentViewController:alertController animated:YES completion:nil];


}
else if([CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied) {
    NSLog(@"Location Services is Never for App");

    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString( @"App Needs Location Services", @"" ) message:NSLocalizedString( @"Please Set Location Services to Always for App", @"" ) preferredStyle:UIAlertControllerStyleAlert];

    UIAlertAction *settingsAction = [UIAlertAction actionWithTitle:NSLocalizedString( @"Settings", @"" ) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];  

    [alertController addAction:settingsAction];

    [self presentViewController:alertController animated:YES completion:nil];

}

Upvotes: 1

Views: 640

Answers (1)

Adrian
Adrian

Reputation: 16715

In your info.plist file, you'll want to include one of the following lines:

If it's always in use, then add this entry to info.plist:

NSLocationAlwaysUsageDescription

The string associated with that entry should be the message you want displayed: `Would you like to enable continual location monitoring even when this app is not in use?"

...or...

You could do NSLocationWhenInUseUsageDescription and a message along the lines of, "Would you like to enable location monitoring only when this app is in use?"

Here's documentation covering this topic

Upvotes: 1

Related Questions