每当用户尝试登录/注册时出现错误时,我都会尝试在可观察对象中显示警报,但到目前为止,警报仅用作视图修饰符并且需要一个按钮才能起作用。我希望它在不使用按钮的情况下运行。
下面是我的代码:
service = build('gmail', 'v1', credentials=creds)
r1 = service.users().messages().list(userId="me", q="utm_source=foo1234").execute()
r2 = service.users().messages().list(userId="me", q="http://www.example.com/page1/?utm_source=foo1234&utm_medium=bar").execute()
这是我的按钮,即注册按钮。
class AppModelView: ObservableObject {
let auth = Auth.auth()
@Published var emailExists = false
var isSignedIn: Bool {
return auth.currentUser != nil
}
func SignIn(email: String, password: String) {
auth.signIn(withEmail: email, password: password) { result, error in
guard result != nil, error != nil else { return }
}
}
func SignUp(withEmail email: String, password: String) {
auth.createUser(withEmail: email, password: password) {result, error in
guard result != nil, error != nil else { return }
if let errCode = AuthErrorCode(rawValue: error!._code) ?? nil {
switch errCode {
case .emailAlreadyInUse:
print("Account Exists")
// show alert here
default:
print("Create User Error: \(String(describing: error))")
}
}
}
}
}
当 firebase 捕捉到错误而不是按下按钮时,是否有某种方法可以切换此警报?
感谢您的帮助。