繁体   English   中英

提示常规iOS定位服务

[英]Prompt for general iOS Location Services

我想问用户是否启用了一般的Locations Services(而不是应用程序特定的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];

}

info.plist文件中,您需要包含以下几行之一:

如果一直使用,则将此条目添加到info.plist

NSLocationAlwaysUsageDescription

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

...要么...

您可以执行NSLocationWhenInUseUsageDescription并显示以下消息:“是否只在使用此应用程序时才启用位置监视?”

这是涵盖此主题的文档

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM