【发布时间】:2019-10-05 20:49:42
【问题描述】:
我已经使用 firebase 电话身份验证在颤振应用中实现了电话号码身份验证。它在 Android 中运行良好。但它在 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!");
}
}
使用的插件
google_sign_in:^4.0.1+3
firebase_auth:^0.11.0
【问题讨论】:
-
我面临着类似的问题。您的应用程序是否在每次重新启动应用程序时都要求 OTP?如果是这样,那么我想我可以告诉你问题
-
@AmitKabra 用户注销或重新安装应用后。
-
每次在 IOS 上重新启动应用程序时,我的应用程序都会要求 OTP。关闭应用程序后,它不会在 Android 上注销。你在IOS上遇到过类似的问题吗?
-
没有。我没有面对。
-
您是否介意分享您的电话登录代码以及重新启动应用时会触发什么?