gpt4 book ai didi

Firebase Phone Auth 在 APK Release模式下不工作

转载 作者:行者123 更新时间:2023-12-05 08:38:34 24 4
gpt4 key购买 nike

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

  1. Firebase Phone Auth not working in release build

  2. Firebase Authentication not working in Signed APK

这两个问题中提到的解决方案都说我需要从 Play 控制台复制 SHA-1 并将其放置在我的应用程序的 Firebase 控制台 SHA-1 中。问题是 我的应用程序不在 Play 商店,我只是签署它并构建 apks,就像我们通常为 apk.relase 所做的那样。我还将 firebase_authfirebase_core 依赖项更新到最新版本。

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


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 key ,但我知道用于调试和 Release模式的 SHA-1 是分开的,这 answer is solution

关于Firebase Phone Auth 在 APK Release模式下不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62384384/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com