Firebase电话验证在APK释放模式下不起作用 [英] Firebase Phone Auth not working in APK Release mode

查看:103
本文介绍了Firebase电话验证在APK释放模式下不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我阅读了以下两个问题,但这些都不是我的问题的解决方案:

I read following two questions but none of these are solution to my problem:

  1. Firebase Phone Auth在发行版本中不起作用

Firebase身份验证在Signed APK中不起作用

这两个问题中提到的解决方案均表明,我需要从Play控制台复制SHA-1,并将其放置在适用于我的应用程序的Firebase控制台SHA-1中.问题是我的应用程序不在游戏商店中,我只是对它签名并构建了apks ,就像我们通常对apk.relase所做的那样.我还将 firebase_auth firebase_core 依赖项更新到最新版本.

Solution mentioned in both of these questions says that I need to copy SHA-1 from Play console and place it in Firebase console SHA-1 for my app. Problem is My app is not on play store, I just signed it and build the apks as we normally do for apk.relase. And I also updated firebase_auth and firebase_core dependencies to latest version.

下面是我的电话验证代码:

Below is my code for phone auth:


  verificationCompleted() {
    return (AuthCredential credential) async {
      await _auth.signInWithCredential(credential).then((AuthResult value) {
        if (value.user != null) {
          Navigator.pop(context);
          Navigator.push(
              context,
              new MaterialPageRoute(
                  builder: (context) => AddContacts(
                        user: value.user,
                      )));
        }
      });
    };
  }

  verificationFailed() {
    return (AuthException exception) {
      Toast.show('Verification Failed: ${exception.code}', context,
          backgroundColor: Colors.red,
          duration: 3,
          backgroundRadius: 5,
          gravity: Toast.BOTTOM);
    };
  }

  codeSent() {
    return (String verificationID, [int forceResendingToken]) {
      showDialog(
          context: context,
          barrierDismissible: false,
          builder: (context) {
            return AlertDialog(
              shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.circular(12)),
              title: Text('Enter 6-Digit Code'),
              content: Column(
                mainAxisSize: MainAxisSize.min,
                children: <Widget>[
                  TextField(
                    style: TextStyle(
                        fontSize: MediaQuery.of(context).size.height * 0.025),
                    controller: _controllerCode,
                    keyboardType: TextInputType.number,
                    maxLength: 6,
                    cursorColor: Colors.black,
                    decoration: InputDecoration(
                      errorText: validateCode(_controllerCode.text),
                      hintText: 'Enter Code',
                      enabledBorder: OutlineInputBorder(
                          borderRadius: BorderRadius.circular(12.0)),
                      focusedBorder: OutlineInputBorder(
                          borderRadius: BorderRadius.circular(12.0)),
                      errorBorder: OutlineInputBorder(
                          borderRadius: BorderRadius.circular(12.0),
                          borderSide: BorderSide(color: Colors.red)),
                      focusedErrorBorder: OutlineInputBorder(
                          borderRadius: BorderRadius.circular(12.0),
                          borderSide: BorderSide(color: Colors.red)),
                    ),
                  ),
                  SizedBox(
                    height: MediaQuery.of(context).size.height * 0.01,
                  ),
                  Row(
                    mainAxisSize: MainAxisSize.min,
                    children: <Widget>[
                      Icon(
                        Icons.info,
                        color: Colors.red,
                        size: MediaQuery.of(context).size.height * 0.03,
                      ),
                      SizedBox(
                        width: MediaQuery.of(context).size.width * 0.02,
                      ),
                      Text(
                        'Wait for Automatic Detection!',
                        style: TextStyle(
                            fontFamily: 'Sogoe',
                            color: Colors.red,
                            fontSize:
                                MediaQuery.of(context).size.height * 0.017),
                      ),
                    ],
                  ),
                  SizedBox(
                    height: MediaQuery.of(context).size.height * 0.01,
                  ),
                  Container(
                    height: MediaQuery.of(context).size.height * 0.06,
                    width: MediaQuery.of(context).size.width,
                    child: FlatButton(
                      padding: EdgeInsets.symmetric(
                          horizontal: MediaQuery.of(context).size.width * .05),
                      shape: RoundedRectangleBorder(
                          borderRadius: BorderRadius.circular(5)),
                      child: Text(
                        "Confirm",
                      ),
                      textColor: Colors.white,
                      color: Colors.lightBlue,
                      onPressed: () async {
                        setState(() {
                          _controllerCode.text.isEmpty
                              ? codeValidate = true
                              : codeValidate = false;
                        });
                        _auth.currentUser().then((user) {
                          if (user != null) {
                            Navigator.pop(context);
                            Navigator.push(
                                context,
                                MaterialPageRoute(
                                    builder: (context) => AddContacts(
                                          user: user,
                                        )));
                          } else {
                            _verifyCode();
                          }
                        });
                        _controllerCode.clear();
                      },
                    ),
                  )
                ],
              ),
            );
          });
      _verificationId = verificationID;
    };
  }

  codeAutoRetrievalTimeout() {
    return (String verificationID) {
      _verificationId = verificationID;
    };
  }

  Future<void> _verifyPhoneNumber(String phone) async {
    _auth.verifyPhoneNumber(
      phoneNumber: phone,
      timeout: const Duration(seconds: 60),
      verificationCompleted: verificationCompleted(),
      verificationFailed: verificationFailed(),
      codeSent: codeSent(),
      codeAutoRetrievalTimeout: codeAutoRetrievalTimeout(),
    );
  }

  Future<void> _verifyCode() async {
    final AuthCredential credential = PhoneAuthProvider.getCredential(
        verificationId: _verificationId, smsCode: _controllerCode.text);
    final FirebaseUser user =
        (await _auth.signInWithCredential(credential)).user;
    final FirebaseUser currentUser = await _auth.currentUser();
    assert(user.uid == currentUser.uid);
    if (user != null) {
      Navigator.pop(context);
      Navigator.push(
          context,
          MaterialPageRoute(
              builder: (context) => AddContacts(
                    user: user,
                  )));
    }
  }

推荐答案

找到了解决方法

是的,我添加了SHA-1密钥,但我知道用于调试和发布模式的SHA-1是分开的,并且此

Yes I added SHA-1 Key but I came to know that SHA-1 for debug and release mode are separate and this answer is solution

这篇关于Firebase电话验证在APK释放模式下不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆