Xamarin Firebase PhoneAuth [英] Xamarin Firebase PhoneAuth

查看:59
本文介绍了Xamarin Firebase PhoneAuth的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I need to create a Xamarin app (Not forms, but separated iOS and Android projects) that has Firebase Phone Auth. Most documentation indicates that there is support for Facebook Auth, but I need PhoneAuth as well.

我找到了Xamarin.Firebase.Auth,显然它支持它,但是我无法实现它,也看不到任何文档说明应使用哪个接口.

I've found Xamarin.Firebase.Auth and apparently it has support for it, but I am not able to implement it nor I see any documentation on which interface should I use for it.

推荐答案

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

Both Android and iOS require setup in the Firebase console and platform specific application setup, so the Google Firebase Auth docs are a required reading and the user needs to notified about phone usage/cost per your app's various countries of distribution legal requirements (noted in the Firebase docs...), iOS needs APN notifications setup, etc...

文档: 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)

// sign the user in via the credential (see the OnVerificationStateChangedCallbacks)

样例PhoneAuthProvider.OnVerificationStateChangedCallbacks类:

Sample PhoneAuthProvider.OnVerificationStateChangedCallbacks class:

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

这篇关于Xamarin Firebase PhoneAuth的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆