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

后端 未结 11 2228
死守一世寂寞
死守一世寂寞 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:23

    In Swift 4, there is an update in its syntax.

    Swift 4

    extension UIAlertController {
    
        func createSettingsAlertController(title: String, message: String) {
    
          let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
    
          let cancelAction = UIAlertAction(title: NSLocalizedString("Cancel", comment: ""), style: .cancel, handler: nil)
          let settingsAction = UIAlertAction(title: NSLocalizedString("Settings", comment: ""), style: .default) { (UIAlertAction) in
            UIApplication.shared.open(URL(string: UIApplicationOpenSettingsURLString)! as URL, options: [:], completionHandler: nil)
          }
    
          alertController.addAction(cancelAction)
          alertController.addAction(settingsAction)
          self.present(alertController, animated: true, completion: nil)
    
       }
    }
    

提交回复
热议问题