【发布时间】:2021-06-12 23:40:52
【问题描述】:
如何将verificationId从SendOtpCodeAsync()发送到SendCode_Button_Clicked()
分享项目代码
IAuth auth;
auth = DependencyService.Get<IAuth>();
private async void SendCode_Button_Clicked(object sender, EventArgs e)
{
bool result = await auth.SendOtpCodeAsync(PhonenumberEntry.Text);
}
android项目代码
[assembly: Dependency(typeof(AuthDriod))]
namespace TestApp_MiniApps.Droid
{
public class AuthDriod : PhoneAuthProvider.OnVerificationStateChangedCallbacks, IAuth
{
private TaskCompletionSource<bool> _phoneAuthTcs;
public Task<bool> SendOtpCodeAsync(string phonenumber)
{
_phoneAuthTcs = new TaskCompletionSource<bool>();
Java.Lang.Long num = (Java.Lang.Long)60;
PhoneAuthOptions options =
PhoneAuthOptions.NewBuilder(FirebaseAuth.Instance)
.SetPhoneNumber(phonenumber) // Phone number to verify
.SetTimeout(num, TimeUnit.Seconds) // Timeout and unit
.SetActivity(Platform.CurrentActivity) // Activity (for callback binding)
.SetCallbacks(this) // OnVerificationStateChangedCallbacks
.Build();
PhoneAuthProvider.VerifyPhoneNumber(options);
return _phoneAuthTcs.Task;
}
public override void OnVerificationCompleted(PhoneAuthCredential credential)
{
}
public override void OnVerificationFailed(FirebaseException exception)
{
_phoneAuthTcs?.TrySetResult(false);
}
public override void OnCodeSent(string verificationId, PhoneAuthProvider.ForceResendingToken forceResendingToken)
{
base.OnCodeSent(verificationId, forceResendingToken);
_phoneAuthTcs?.TrySetResult(true);
}
}//end of class
}
分享项目界面
namespace TestApp_MiniApps.Views.Xamarin.FireBase
{
public interface IAuth
{
Task<bool> SendOtpCodeAsync(string phonenumber);
}//end of class
}
【问题讨论】:
-
堆栈跟踪应该显示导致异常的行号
-
感谢您回来。是的,错误是因为我将字符串从
share-project传递到android-project。我也尝试转换为String和ToString -
我怀疑这就是原因。你正在做的唯一明显的演员是Java.Lang.Long。如果您按照我的建议查看堆栈跟踪,它将确认这一点
-
问题是什么?当你尝试它时会发生什么?这不编译吗?或者你在运行时遇到异常?哪一行代码失败了?
-
问题我如何发送价值。我在谷歌上看,但很难找到一些类似的。你知道我怎么发送它,或者我可以看看你可能有的一些链接吗?
标签: c# android xamarin xamarin.forms xamarin.android