firebase Flutter - OTP验证在调试模式下工作,但在iOS发布模式下不工作

oxcyiej7  于 2023-01-14  发布在  Flutter
关注(0)|答案(2)|浏览(178)

我正在构建一个flutter应用程序,遇到了一个以前从未见过的奇怪问题。我正在使用Firebase auth通过OTP进行手机验证。
然而,我只在iOS的调试模式下收到OTP,而不是在发布模式下。这两种情况下,它在Android上都工作得很好。我不知道我做错了什么,因为我在iOS根目录下有更新的GoogleService-info.plist。你们有什么想法吗?
这是我验证OTP时的工作流程:-

Future<void> verifyPhone(String phoneNumber, ) async {
    await FirebaseAuth.instance.verifyPhoneNumber(
        phoneNumber: phoneNumber,
        timeout: const Duration(seconds: 60),
        verificationCompleted: (PhoneAuthCredential credential) {
          print('Auth completed');
        },
        verificationFailed: (FirebaseAuthException e) {
          print(e);
          print('Auth failed');
        },
        codeSent: (String verificationId, int? resendToken) {
          print('OTP sent');
          verId = verificationId;
          Queries.instance.verId = verificationId;
          print(verId + '........');
        },
        codeAutoRetrievalTimeout: (String verificationId) {
          print('Timeout');
        }
    );
  }
nlejzf6q

nlejzf6q1#

要使某些Firebase相关功能在iOS中工作,您必须将Firebase项目与Apple推送通知服务的APN密钥链接。
你能做的事,
1.前往Apple开发者控制台并创建APN密钥。
1.导出密钥并将其添加到Firebase控制台。
作为参考,
https://www.kodeco.com/20201639-firebase-cloud-messaging-for-ios-push-notifications

jv2fixgn

jv2fixgn2#

以下是我在OTP验证方面的职责:

verifyPhoneNumber() async {
    await FirebaseAuth.instance.verifyPhoneNumber(
      phoneNumber: widget.phoneNumberControllerValueText,
      verificationCompleted: (PhoneAuthCredential credential) async {
        UserCredential userCredential =
            await FirebaseAuth.instance.signInWithCredential(credential);
        if (userCredential.user != null) {
          log('verifyPhoneNumber - User logged in.');

          if (mounted) {
            Navigator.pushAndRemoveUntil(
              context,
              MaterialPageRoute(
                builder: (context) {
                  return const HomeScreen();
                },
              ),
              (Route<dynamic> route) => false,
            );
          }
        }
      },
      verificationFailed: (FirebaseAuthException e) {
        log('e.toString: ${e.message.toString()}');
        ScaffoldMessenger.of(context).showSnackBar(
          SnackBar(
            content: Text(
              e.message.toString(),
            ),
          ),
        );
        if (e.code == 'invalid-phone-number') {
          log('The provided phone number is not valid.');
          ScaffoldMessenger.of(context).showSnackBar(
            const SnackBar(
              content: Text(
                'The provided phone number is not valid.',
              ),
            ),
          );
        }
      },
      codeSent: (String verificationId, int? resendToken) async {
        tempVerificationId = verificationId;
      },
      codeAutoRetrievalTimeout: (String verificationId) {
        tempVerificationId = verificationId;
      },
      timeout: const Duration(seconds: 60),
    );
  }

您可以使用函数进行交叉验证以检查差异,或者,如果您想要完整的源代码,可以在以下位置获得:
https://github.com/dharambudh1/firebase-otp-integration-demo/

相关问题