Firebaseauth验证浮力iOS中的浮力崩溃
当我调用verifyphoneNumber方法时,我会遇到此错误:
我的代码在Android中正常工作。只有在iOS中,才会给我这个错误。我在Stackoverflow和GitHub上检查了很多问题,并确保我的GoogleService-info.plist在正确的文件夹中。我仅通过Xcode导入GoogleService-info.plist,并且在Xcode-&gt中的CopyBundleresources部分中也添加了它。跑步者 - >建筑重点。我还看到很多地方都需要在Xcode中的URL类型中添加Reversed_client_id。完成此操作并检查了信息。 我已经做了所有事情,但仍然不知道是什么原因引起了问题。
我的移动AUTH代码:
import 'package:firebase_auth/firebase_auth.dart';
import 'package:[**package_name**]/functions/typedef.dart';
import 'package:[**package_name**]/helpers/log_helper.dart';
class MobileAuth{
MobileAuth(
this.mobileNumber,
this.afterCodeSent,
this.verificationCompleted,
this.verificationFailed,
this.autoTimeout,
this.ifOtpFailed,
this.afterOtpSend);
final String mobileNumber;
final AfterCodeSent afterCodeSent;
final PhoneAuthVerificationCompleted verificationCompleted;
final PhoneAuthVerificationFailed verificationFailed;
final AuthFailedMessage autoTimeout;
final AuthFailedMessage ifOtpFailed;
final AfterOtpSend afterOtpSend;
FirebaseAuth auth = FirebaseAuth.instance;
/// to sent the code to the given mobile number
void initialAuth() async{
await auth.verifyPhoneNumber(
phoneNumber: mobileNumber,
verificationCompleted: (PhoneAuthCredential credential) {
verificationCompleted(credential);
},
verificationFailed: (FirebaseAuthException e) {
verificationFailed(e);
},
codeSent: (String verificationId, int? resendToken) {
afterCodeSent(verificationId, resendToken ?? 0);
},
timeout: const Duration(seconds: 15),
codeAutoRetrievalTimeout: (String verificationId) {
autoTimeout(verificationId);
},
);
}
/// check otp by submitting to the auth api
void verifyOtp(String smsCode, String verificationId) async{
// Create a PhoneAuthCredential with the code
PhoneAuthCredential credential = PhoneAuthProvider.credential(verificationId: verificationId, smsCode: smsCode);
// Sign the user in (or link) with the credential
try{
UserCredential userCredential = await auth.signInWithCredential(credential);
LogHelper.log("After sending OTP: ${userCredential.user?.uid}");
afterOtpSend(userCredential);
}catch(e){
LogHelper.log("After sending OTP ${e.toString()}");
ifOtpFailed(e.toString());
}
}
void resendVerificationCode(int token) {
auth.verifyPhoneNumber(
forceResendingToken: token,
phoneNumber: mobileNumber,
verificationCompleted: (PhoneAuthCredential credential) {
verificationCompleted(credential);
},
verificationFailed: (FirebaseAuthException e) {
verificationFailed(e);
},
codeSent: (String verificationId, int? resendToken) {
afterCodeSent(verificationId , resendToken ?? 0);
},
timeout: const Duration(seconds: 60),
codeAutoRetrievalTimeout: (String verificationId) {
autoTimeout(verificationId);
},
);
}
}
我在类似的状态窗口小部件的方法中称其为:
@override
void initState(){
String mobileNumber = "${widget.countryCode} ${widget.phoneNumber}";
mobileAuth = MobileAuth(mobileNumber, afterCodeSent,
verificationCompleted, verificationFailed, autoTimeout, ifOtpFailed, afterOtpSend);
sendOtpToPhone();
}
void sendOtpToPhone(){
mobileAuth.initialAuth();
}
该代码在Android调试和发行模式中正常工作,因此我仅在iOS中遇到此问题。当我调用sendotptophone();
- &gt时,崩溃会崩溃。 mobileAuth.InitialAuth();
- > auth.verifyphoneNumber();
我已经确定airfify.verifyphonenumber();
仅引起错误,因为如果我评论了代码段发生。
还尝试了扑打清洁,我正在使用firebase_auth:3.3.16。还尝试了3.3.14。
I got this error when i call verifyPhoneNumber method:
My code works fine in android. Only in IOS it throws me this error. I checked a lot of issues on stackoverflow and github and have made sure that my GoogleService-Info.plist is in the right folder. I imported GoogleService-Info.plist through Xcode only and it is also added in CopyBundleResources section in Xcode-> Runner -> BuildPhases. Also a lot of places I saw that I need to add REVERSED_CLIENT_ID in URL Types in Xcode. Done this and also checked Info.plist that my REVERSED_CLIENT_ID is added correctly.
I have done everything but still don't know what is causing the issue.
My code for mobile auth:
import 'package:firebase_auth/firebase_auth.dart';
import 'package:[**package_name**]/functions/typedef.dart';
import 'package:[**package_name**]/helpers/log_helper.dart';
class MobileAuth{
MobileAuth(
this.mobileNumber,
this.afterCodeSent,
this.verificationCompleted,
this.verificationFailed,
this.autoTimeout,
this.ifOtpFailed,
this.afterOtpSend);
final String mobileNumber;
final AfterCodeSent afterCodeSent;
final PhoneAuthVerificationCompleted verificationCompleted;
final PhoneAuthVerificationFailed verificationFailed;
final AuthFailedMessage autoTimeout;
final AuthFailedMessage ifOtpFailed;
final AfterOtpSend afterOtpSend;
FirebaseAuth auth = FirebaseAuth.instance;
/// to sent the code to the given mobile number
void initialAuth() async{
await auth.verifyPhoneNumber(
phoneNumber: mobileNumber,
verificationCompleted: (PhoneAuthCredential credential) {
verificationCompleted(credential);
},
verificationFailed: (FirebaseAuthException e) {
verificationFailed(e);
},
codeSent: (String verificationId, int? resendToken) {
afterCodeSent(verificationId, resendToken ?? 0);
},
timeout: const Duration(seconds: 15),
codeAutoRetrievalTimeout: (String verificationId) {
autoTimeout(verificationId);
},
);
}
/// check otp by submitting to the auth api
void verifyOtp(String smsCode, String verificationId) async{
// Create a PhoneAuthCredential with the code
PhoneAuthCredential credential = PhoneAuthProvider.credential(verificationId: verificationId, smsCode: smsCode);
// Sign the user in (or link) with the credential
try{
UserCredential userCredential = await auth.signInWithCredential(credential);
LogHelper.log("After sending OTP: ${userCredential.user?.uid}");
afterOtpSend(userCredential);
}catch(e){
LogHelper.log("After sending OTP ${e.toString()}");
ifOtpFailed(e.toString());
}
}
void resendVerificationCode(int token) {
auth.verifyPhoneNumber(
forceResendingToken: token,
phoneNumber: mobileNumber,
verificationCompleted: (PhoneAuthCredential credential) {
verificationCompleted(credential);
},
verificationFailed: (FirebaseAuthException e) {
verificationFailed(e);
},
codeSent: (String verificationId, int? resendToken) {
afterCodeSent(verificationId , resendToken ?? 0);
},
timeout: const Duration(seconds: 60),
codeAutoRetrievalTimeout: (String verificationId) {
autoTimeout(verificationId);
},
);
}
}
And i call this in my statefull widget init method like this:
@override
void initState(){
String mobileNumber = "${widget.countryCode} ${widget.phoneNumber}";
mobileAuth = MobileAuth(mobileNumber, afterCodeSent,
verificationCompleted, verificationFailed, autoTimeout, ifOtpFailed, afterOtpSend);
sendOtpToPhone();
}
void sendOtpToPhone(){
mobileAuth.initialAuth();
}
The code works fine in android debug and release mode, so I only have this issue in IOS. Crashes when I call sendOtpToPhone();
-> mobileAuth.initialAuth();
-> auth.verifyPhoneNumber();
I have know for sure that auth.verifyPhoneNumber();
is only causing the error, because if I comment that segment of code then no crash is happening.
Also have tried flutter clean and i am using firebase_auth: 3.3.16 . Also tried it with 3.3.14.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论