[英]Firebase Phone Auth (Flutter) is not working in some iOS devices
我已經在使用Firebase電話身份驗證的Flutter應用中實現了電話號碼身份驗證。 在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
嘗試將REVERSE_CLIENT_ID自定義URL方案添加到您的Xcode項目中。
根據firebase文檔:
iOS設置說明:如果您使用的模擬器(無法使用APN的模擬器)或未在您使用的設備上設置APN,則應用驗證可能會使用APN,您必須將URL方案設置為GoogleServices-Info.plist文件中的REVERSE_CLIENT_ID。
如何向您的Xcode項目中添加自定義URL方案:
從這里引用:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.