I am trying to present an alert for password reset link sent through Firebase with this code inside a func, but it says deprecated and my alert is not showing. Any help to solve?
Thanks!
func resetPassword() {
let alert = UIAlertController(title: "Reset Password", message: "Inserisci la tua e-mail per resettare la password", preferredStyle: .alert)
alert.addTextField { (password) in
password.placeholder = "Email"
}
let proceed = UIAlertAction(title: "Reset", style: .default) { (_) in
// Sending email Link
if alert.textFields![0].text! != "" {
withAnimation {
self.isLoading.toggle()
}
Auth.auth().sendPasswordReset(withEmail: alert.textFields![0].text!) { (err) in
withAnimation {
self.isLoading.toggle()
}
if err != nil {
print(err?.localizedDescription as Any)
self.alertMsg = err!.localizedDescription
self.alert.toggle()
return
}
// Conferma invio link
self.alertMsg = "Il link per il reset della password è stato correttamente inviato"
print(self.alertMsg)
self.alert.toggle()
}
}
}
let cancel = UIAlertAction(title: "Annulla", style: .destructive, handler: nil)
alert.addAction(cancel)
alert.addAction(proceed)
***UIApplication.shared.windows.first?.rootViewController?.present(alert, animated: true)***
}
SwiftUI provided us standard way to show alert like this, you can use this approach to achieve what you're looking for