我使用firebase phone auth在flutter应用程序中实现了电话号码身份验证。它在安卓系统中运行良好。但它在iOS中无法正常工作,因为许多用户在提交短信验证代码后面临错误,尽管许多其他用户使用该应用程序非常好。出现这种情况的可能原因是什么?我已经提交了下面的代码。
数字提交
void _verifyPhoneNumber() async {
final PhoneVerificationCompleted verificationCompleted =
(AuthCredential phoneAuthCredential) async {
final FirebaseUser user =
await _auth.signInWithCredential(phoneAuthCredential);
if (user != null) {
phone = user.phoneNumber;
fid = user.uid;
saveLogin(context);
} else {
_showErrorDialog("User Verification Error!");
}
};
final PhoneVerificationFailed verificationFailed =
(AuthException authException) {
_showErrorDialog("Phone Verification Failed");
};
final PhoneCodeSent codeSent =
(String verificationId, [int forceResendingToken]) async {
_verificationId = verificationId;
setState(() {
_title = "Verify SMS Code";
phoneInput = false;
phoneSubmit = false;
codeInput = true;
codeSubmit = true;
});
};
final PhoneCodeAutoRetrievalTimeout codeAutoRetrievalTimeout =
(String verificationId) async {
_verificationId = verificationId;
setState(() {
_title = "Verify SMS Code";
phoneInput = false;
phoneSubmit = false;
codeInput = true;
codeSubmit = true;
});
};
await _auth.verifyPhoneNumber(
phoneNumber: "+880" + _mobileNumber,
timeout: const Duration(seconds: 5),
verificationCompleted: verificationCompleted,
verificationFailed: verificationFailed,
codeSent: codeSent,
codeAutoRetrievalTimeout: codeAutoRetrievalTimeout);
}
代码提交
void _signInWithPhoneNumber(String _code) async {
final AuthCredential credential = PhoneAuthProvider.getCredential(
verificationId: _verificationId,
smsCode: _code,
);
final FirebaseUser user = await _auth.signInWithCredential(credential);
if (user != null) {
phone = user.phoneNumber;
fid = user.uid;
saveLogin(context);
} else {
_showErrorDialog("User Verification Error!");
}
}
使用的插件
谷歌登录:^4.0.1+3
firebase认证:^0.11.0