Gin*_*ino 2 firebase xamarin firebase-authentication
我需要创建一个具有Firebase Phone Auth的Xamarin应用程序(不是表单,而是分开的iOS和Android项目)。大多数文档都表明支持Facebook Auth,但我也需要PhoneAuth。
我找到了Xamarin.Firebase.Auth,显然它支持它,但是我无法实现它,也看不到任何文档应该使用哪个接口。
Android和iOS都需要在Firebase控制台中进行设置以及特定于平台的应用程序设置,因此必须阅读Google Firebase Auth文档,并且用户需要根据您应用的各个发行国家/地区的法律法规要求通知手机使用/费用(请注意Firebase文档...),iOS需要设置APN通知,等等...
Xamarin.Firebase.Auth示例Android :文件: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
Run Code Online (Sandbox Code Playgroud)
//通过凭据登录用户(请参阅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);
}
}
Run Code Online (Sandbox Code Playgroud)
Xamarin.Firebase.iOS.Auth示例的iOS :文件: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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1018 次 |
| 最近记录: |