gpt4 book ai didi

firebase - Xamarin Firebase PhoneAuth

转载 作者:行者123 更新时间:2023-12-04 00:42:28 25 4
gpt4 key购买 nike

我需要创建一个具有 Firebase Phone Auth 的 Xamarin 应用程序(不是表单,而是独立的 iOS 和 Android 项目)。大多数文档表明支持 Facebook Auth,但我也需要 PhoneAuth。

我找到了 Xamarin.Firebase.Auth,显然它支持它,但我无法实现它,也没有看到任何关于我应该使用哪个接口(interface)的文档。

最佳答案

Android 和 iOS 都需要在 Firebase 控制台和特定于平台的应用程序设置中进行设置,因此 Google Firebase Auth 文档是必读的,并且用户需要根据您的应用程序了解电话使用情况/费用不同国家/地区的分发法律要求(在 Firebase 文档中注明...),iOS 需要 APN 通知设置等...

Android 通过 Xamarin.Firebase.Auth 示例:

文档:https://firebase.google.com/docs/auth/android/phone-auth

PhoneAuthCallbacks phoneAuthCallbacks = new PhoneAuthCallbacks();
PhoneAuthProvider.Instance.VerifyPhoneNumber("555-555-5555", 60, TimeUnit.Seconds, this, phoneAuthCallbacks);
// You can now obtain a user credential via the verification code and verification ID and

//通过凭据让用户登录(请参阅 OnVerificationStateChangedCallbacks)

示例 PhoneAuthProvider.OnVerificationStateChangedCallbacks 类:

public class PhoneAuthCallbacks : PhoneAuthProvider.OnVerificationStateChangedCallbacks
{
public override void OnVerificationCompleted(PhoneAuthCredential credential)
{
// This callback will be invoked in two situations:
// 1 - Instant verification. In some cases the phone number can be instantly
// verified without needing to send or enter a verification code.
// 2 - Auto-retrieval. On some devices Google Play services can automatically
// detect the incoming verification SMS and perform verification without
// user action.
}

public override void OnVerificationFailed(FirebaseException exception)
{
// This callback is invoked in an invalid request for verification is made,
// for instance if the the phone number format is not valid.
}

public override void OnCodeSent(string verificationId, PhoneAuthProvider.ForceResendingToken forceResendingToken)
{
// The SMS verification code has been sent to the provided phone number, we
// now need to ask the user to enter the code and then construct a credential
// by combining the code with a verification ID.
base.OnCodeSent(verificationId, forceResendingToken);
}
}

iOS 通过 Xamarin.Firebase.iOS.Auth 示例:

文档:https://firebase.google.com/docs/auth/ios/phone-auth

var verificationID = await PhoneAuthProvider.DefaultInstance.VerifyPhoneNumberAsync("555-555-5555", null);
// You can now obtain a user credential via the verification code and verification ID.
// Now you can sign the user in via the credential

关于firebase - Xamarin Firebase PhoneAuth,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49394281/

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