flutter - Flutter Firebase Phone 身份验证仅适用于 Android,不适用于 iOS
问题描述
我正在开发一个新的 Flutter 项目,我需要在其中使用 Firebase 实现电话身份验证。
我刚刚完成了那部分代码的开发并在真实设备上进行了测试。
这里有我用来验证电话号码的功能:
_verifyPhone() async {
print("Estoy en veryfyphone "+'+34${widget.phone}');
await FirebaseAuth.instance.verifyPhoneNumber(
phoneNumber: '+34${widget.phone}',
verificationCompleted: (PhoneAuthCredential credential) async {
await FirebaseAuth.instance
.signInWithCredential(credential)
.then((value) async {
if (value.user != null) {
Navigator.pushAndRemoveUntil(
context,
MaterialPageRoute(builder: (context) => Dashboard()),
(route) => false);
}
});
},
verificationFailed: (FirebaseAuthException e) {
print(e.message);
},
codeSent: (String verficationID, int resendToken) {
setState(() {
_verificationCode = verficationID;
});
},
codeAutoRetrievalTimeout: (String verificationID) {
setState(() {
_verificationCode = verificationID;
});
},
timeout: Duration(seconds: 120));
}
在这里,您有一段使用 PinPut 小部件处理接收到的 SMS 代码的代码:
PinPut(
fieldsCount: 6,
textStyle: const TextStyle(fontSize: 25.0, color: Colors.white),
eachFieldWidth: 40.0,
eachFieldHeight: 55.0,
focusNode: _pinPutFocusNode,
controller: _pinPutController,
submittedFieldDecoration: pinPutDecoration,
selectedFieldDecoration: pinPutDecoration,
followingFieldDecoration: pinPutDecoration,
pinAnimationType: PinAnimationType.fade,
onSubmit: (pin) async {
try {
await FirebaseAuth.instance
.signInWithCredential(PhoneAuthProvider.credential(
verificationId: _verificationCode, smsCode: pin))
.then((value) async {
if (value.user != null) {
Navigator.pushAndRemoveUntil(
context,
MaterialPageRoute(builder: (context) => Dashboard()),
(route) => false);
}
});
} catch (e) {
FocusScope.of(context).unfocus();
_scaffoldkey.currentState
.showSnackBar(SnackBar(content: Text('invalid OTP')));
}
},
),
我的问题是它仅适用于该项目的 Android 应用程序。
启动 iOS 应用程序时没有收到短信。
我已经为 iOS 实现了所有需要的设置。
解决方案
推荐阅读
- batch-file - 如何根据 DD.MM.YY 或 DD.MM.YYYY 格式的文件名末尾的日期找出目录中的最新文件?
- wordpress - 如何在 wordpress 帖子中调用 [here-api]?
- java - 在客户端 PC 上与 MS Office 通信
- import - 如何将数据导入 SAS 会话,以便开始分析?
- css - Bootstrap 表单在验证时会改变大小
- javascript - 节点 Passport-azure-ad 错误:“未知身份验证策略“oauth-bearer””
- types - 键入规则中的迭代 (?)
- wxpython - WxPython - GUI 冻结
- email - 使用 VB.net 自动填充电子邮件
- c++ - 析构函数会在 C++ 中自动调用 delete[] 吗?