我正在尝试向Firebase和Kotlin进行注册。 看一下docs,我看到了Java中的所有例子。因此,当我尝试在Kotlin中实施时,我无法使其发挥作用。
在Java中应该是这样的:
// [START create_user_with_email]
mAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
// Sign in success, update UI with the signed-in user's information
FirebaseUser user = mAuth.getCurrentUser();
} else {
// If sign in fails, display a message to the user.
......
}
// [START_EXCLUDE]
.......
// [END_EXCLUDE]
}
});
// [END create_user_with_email]
但是当我尝试在kotlin中实现这样的时候:
// [START create_user_with_email]
mAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(this, OnCompleteListener<AuthResult> { task ->
if (task.isSuccessful) {
// Sign in success, update UI with the signed-in user's information
val user = mAuth.currentUser
} else {
......
}
// [START_EXCLUDE]
.....
// [END_EXCLUDE]
})
// [END create_user_with_email]
而且我不知道如何解决它。
答案 0 :(得分:15)
我已通过以下方式使用电子邮件和密码实施Firebase注册,并且可以正常运行:
this.firebaseAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener { task: Task<AuthResult> ->
if (task.isSuccessful) {
//Registration OK
val firebaseUser = this.firebaseAuth.currentUser!!
} else {
//Registration error
}
}
答案 1 :(得分:0)
auth.createUserWithEmailAndPassword(email,pass).addOnCompleteListener(object: OnCompleteListener<AuthResult>{
override fun onComplete(p0: Task<AuthResult>) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
})