提示使用一般iOS定位服务



我想请用户启用通用定位服务(而不是应用程序特定的定位服务),如果作为一个整体,他们从未被提示为应用程序启用它。

有没有一种方法可以提示用户在每次打开应用程序并将其禁用时整体打开定位服务?

在其他线程中找到代码,但它是特定于应用程序的,而不是一般的定位服务:

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 AppnnSettings->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,并发送一条类似"你想只在使用该应用程序时启用位置监控吗?"的消息

以下是涉及此主题的文档

最新更新