I have an alert that pops if location services are off or denied that will direct the user to Settings so that Location Services can be turned on. It is shown by setting a state variable, showAlert to true. The code I have is:
Alert(title: Text("Location Services"),
message: Text("Location Services is off or denied. The app must have your location to function. Please enable Location Services for the app in Settings."),
primaryButton: .default(Text("Settings"), action: {
self.showAlert = false // my attempt to clear the alert
UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!)
}),
secondaryButton: .default(Text("Okay")))
The issue I have is that the alert doesn't dismiss when the user clicks the settings button to go to Settings to turn on Location Services. So, when the user returns to the app after enabling them, the alert is still present stating services are not on. It is a bad user experience and I would like to have it dismissed before the user can read it upon return. As you can see from the code, I tried setting the showAlert state variable to false, but that didn't work. Any thoughts?