How can I prompt the user to turn on location services after user has denied their use

后端 未结 11 2255
死守一世寂寞
死守一世寂寞 2020-11-29 20:06

I have an application with an explicit user interaction that makes use of the user\'s current location. If the user denies access to location services, I would still like su

11条回答
  •  孤街浪徒
    2020-11-29 20:28

    AlertViews are deprecated in iOS 8. There is now a better way to handle alerts using the new AlertController:

    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString( @"Enter your title here", @"" ) message:NSLocalizedString( @"Enter your message here.", @"" ) preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString( @"Cancel", @"" ) style:UIAlertActionStyleCancel handler:nil];
    UIAlertAction *settingsAction = [UIAlertAction actionWithTitle:NSLocalizedString( @"Settings", @"" ) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
       [[UIApplication sharedApplication] openURL:[NSURL URLWithString:
                                                        UIApplicationOpenSettingsURLString]];
    }];
    
    [alertController addAction:cancelAction];
    [alertController addAction:settingsAction];
    
    [self presentViewController:alertController animated:YES completion:nil];
    

提交回复
热议问题