首页 > 解决方案 > 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 实现了所有需要的设置。

标签: flutterfirebase-authentication

解决方案


推荐阅读