Firebase SMS验证

问题描述

我正在为自己的Flutter应用程序使用Firebase身份验证。我配置了Firebase并开始使用此代码

      login() async {
        await FirebaseAuth.instance
        .verifyPhoneNumber(
          phoneNumber: '+447123123456',verificationCompleted: (PhoneAuthCredential credential) {},verificationFailed: (FirebaseAuthException e) {
            print("Code  Failed 2");
            print(e);
          },codeSent: (String verificationId,int resendToken) {
            print("Code Send");
          },codeAutoRetrievalTimeout: (String verificationId) {},)
      );
    }

提取代码时会打印

    I/BiChannelGoogleApi(13432): [FirebaseAuth: ] getGoogleApiForMethod() returned Gms: 
    com.google.firebase.auth.api.internal.zzaq@3665a442
    I/Flutter (13432): Code  Failed 2
    I/Flutter (13432): [firebase_auth/null] null

无法跟踪错误消息,并且验证码未发送到我的设备,我将此链接用作参考https://firebase.flutter.dev/docs/auth/phone/

解决方法

它可能无法工作的几种可能原因可能是

  1. 您可能尚未在Firebase控制台中启用sms-verification验证。
  2. 在测试期间,请检查您是通过仿真器还是实际设备连接到互联网。
  3. 其他可能的原因可能是模拟器的android图像。尝试以其他支持Google Play服务的现代图片进行测试。