ios - 在删除帐户之前发出“你确定吗”警报
问题描述
我有一个使用 Firebase 数据库的应用程序。我还有一个连接到按钮的功能来删除他们的 firebase 帐户,但我需要发出某种警报来询问用户“你确定吗?”。
删除功能:
let user = Auth.auth().currentUser
let firebase = Database.database().reference()
// ... removes auth account
user?.delete(completion: { (error) in
if let error = error {
print(error.localizedDescription)
} else {
print("Auth Deleted")
}
})
// ... removes account from database
firebase.child("Users/Riders").child((user?.uid)!).removeValue { (error, ref) in
if error != nil {
print("error \(String(describing: error))")
} else {
print("Database acct deleted!")
}
}
self.logOutAction(self)
我现在需要创建一个警报,当用户按下删除按钮时,会弹出一个警报,其中包含 2 个选项是或否。如果他们按下是,“删除”功能将被激活,如果他们按下否,它会取消操作。
我知道如何创建警报,只是不知道如何在用户按下“是”时实现“删除”功能
解决方案
在运行此删除功能之前,您可以查看UIAlertController来完成此操作。您可以为实际调用删除函数的确认操作设置处理程序。确保从主线程运行它。
例如,连接到删除按钮的函数可能如下所示:
let alert = UIAlertController(title: "Delete Account", message: "Are you sure you want to delete this account?", preferredStyle: .alert)
let deleteAction = UIAlertAction(title: "Delete", style: .destructive, handler: { (action) in
print("Call the deletion function here")
self.processDelete()
})
alert.addAction(deleteAction)
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel)
alert.addAction(cancelAction)
self.present(alert, animated: true, completion: nil)
推荐阅读
- angular - 如何动态加载templateUrl取决于值
- vba - 使用“选择”在文件夹中的所有文件上运行宏的问题
- firebase - iOS 上的 Firebase 身份验证
- javascript - Vue-CLI 导入全局 scss 文件
- sql - 如何从oracle中的另一张表中获取一张表的id计数
- algorithm - 我想打印等差数列三角形
- javascript - 流:日期与字符串不兼容
- android - 从 RecyclerView 中删除项目并将其插入到另一个位置
- ios - 如何声明自定义对象,例如。可编码类中的计时器
- reactjs - 带有用于用户输入的自定义输入的 react-datepicker 不起作用