提示一般iOS位置服务

时间:2015-12-16 01:23:21

标签: ios objective-c 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];

}

1 个答案:

答案 0 :(得分:1)

NSLocationWhenInUseUsageDescription文件中,您希望包含以下其中一行:

如果它一直在使用,请将此条目添加到f2

a

与该条目相关联的字符串应该是您想要显示的消息:“即使不使用此应用程序,您是否要启用连续位置监控?"

...或...

您可以执行a[1]和一条消息,"您是否只在此应用正在使用时启用位置监控?"

pycountry