[英]Flutter web: Firestore work in run debug mode and don't work in bilud release mode
[英]Flutter - OTP Verification works in debug mode but not release mode iOS
我正在构建一个 flutter 应用程序,遇到了一个我以前从未见过的奇怪问题。 我正在使用 Firebase 身份验证通过 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');
}
);
}
要在 iOS 中使用一些与 Firebase 相关的功能,您必须将您的 Firebase 项目与 Apple 推送通知服务的 APN 密钥链接起来。
你能做的事情,
以供参考,
https://www.kodeco.com/20201639-firebase-cloud-messaging-for-ios-push-notifications
下面提到的是我的 function 用于 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),
);
}
您可以与您的 function 交叉验证以检查差异,或者如果您想要完整的源代码,可以在以下位置获得:
https://github.com/dharambudh1/firebase-otp-integration-demo/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.