Android 和 iOS 都需要在 Firebase 控制台和平台特定的应用程序设置中进行设置,因此Google Firebase 身份验证文档是必读的,并且用户需要根据您的应用程序了解手机使用情况/费用各个国家/地区的分发法律要求(在 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