Firebase电话身份验证(Flutter)在某些iOS设备中不起作用

时间:2019-05-19 04:24:27

标签: android ios dart flutter

我已经使用Firebase电话身份验证在Flutter应用中实现了电话号码身份验证。在Android中运行正常。但这在iOS中无法正常运行,因为许多用户在提交短信验证码后都遇到了错误,尽管很多其他人都很好地使用了该应用。这种情况可能是什么原因?我已经在下面提交了我的代码。

提交号码

           let rl = readline.createInterface({ input: process.stdin, output: process.stdout, terminal: true });

        if (flags.interactive || args.cmd === 'bash') {
          execService.exec(this, id, appUrl, { Detach: false, Tty: flags.tty }).then(response => {

            let stream = response.data;
            let socket = stream.socket;

            socket.on('data', (data: string) => {
              process.stdin.pause();
              if (!firstLine) {
                process.stdout.write(data);
              }
              firstLine = false;
              process.stdin.resume()
            })

            process.stdin.on('data', i => {
              socket.write(i.toString())
              if (i == DetachKey) {
                rl.emit('SIGINT')
              }
            })

            rl.on('SIGINT', function () {
              // stop input
              socket.emit('end')
              process.stdin.pause()
              process.stdout.write(exec_exit_msg)
              process.exit(0)
            })

          });
        }

提交代码

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);
  }

使用的插件

  

google_sign_in:^ 4.0.1 + 3

     

firebase_auth:^ 0.11.0

1 个答案:

答案 0 :(得分:0)

尝试将REVERSE_CLIENT_ID自定义URL方案添加到您的Xcode项目中。

根据firebase文档:

iOS设置说明:如果您使用的设备上未使用模拟器(其中APN不起作用)或未设置APN,则应用程序验证可能会使用APN,您必须将URL方案设置为GoogleServices-Info的REVERSE_CLIENT_ID。 plist文件。

如何在Xcode项目中添加自定义URL方案:

  1. 打开项目配置:在左树视图中双击项目名称。从“目标”部分中选择您的应用,然后选择“信息”选项卡,然后展开“ URL类型”部分。
  2. 单击+按钮,然后为您的反向客户ID添加URL方案。要找到此值,请打开Goog​​leService-Info.plist配置文件,然后查找REVERSED_CLIENT_ID密钥。复制该键的值,然后将其粘贴到配置页上的“ URL方案”框中。将其他字段留空。

从这里引用:

https://pub.dev/packages/firebase_auth

https://firebase.google.com/docs/auth/ios/phone-auth