Direct FirebaseUI to Phone login in iOS App

Viewed 614

I am trying to implement FirebaseUI in my iOS app for Phone Authentication. But the UI that opens up shows the "Sign in with mail" optionFirebaseUI

I need it to go directly to the phone login page- Phone Login

How can that be done in FirebaseUI. Also, how can I fill the phone number field before this view appears?

3 Answers

You should have made an object of type FUIAuth somewhere in your code, perhaps in a view controller.

// Perhaps you made it by doing this.
let authUI = FUIAuth.defaultAuthUI()

// You should also have a `FUIPhoneAuth` object somewhere.
let phoneProvider = FUIPhoneAuth(authUI: authUI)

// This will suppress the "Sign in with mail button"
authUI.isSignInWithEmailHidden = true

// This will bypass that welcome screen altogether 
// (because there is only a single element in the array).
authUI.providers = [phoneProvider]

If you already know the phone number, you can do this. Assuming self is the view controller presenting the firebase ui.

let phoneNumber = "+12345558888"
phoneProvider.signIn(withPresenting: self, phoneNumber: phoneNumber)

This will open the phone authentication screen directly

if let authUI = FUIAuth.defaultAuthUI() {

        let phoneProvider = FUIPhoneAuth(authUI: authUI)

        authUI.delegate = self

        authUI.providers = [phoneProvider]

        authUI.signIn(withProviderUI: phoneProvider, presenting: self, defaultValue: nil)
}

Should called from a controller.

Let's supose that you have a view controller with a button to start the phone validation. This is the code that should be included in the button (obj-c)

- (IBAction)btnPhoneValidation:(id)sender {
    FUIAuth *authUI = [FUIAuth defaultAuthUI];
    authUI.delegate = self;

The following array may contain different options for validate the user (with Facebook, with google, e-mail...), in this case we only need the phone method, but probably you have also the e-mail method included in the array

NSArray<id<FUIAuthProvider>> * providers = @[ [[FUIEmailAuth alloc] init],[[FUIPhoneAuth alloc]initWithAuthUI:[FUIAuth defaultAuthUI]]];
authUI.providers = providers;

You can present the screen asking for the user number with the following method.

FUIPhoneAuth *provider = authUI.providers.firstObject;
[provider signInWithPresentingViewController:self phoneNumber:nil];

This is the default way to present several options.

//    UINavigationController *authViewController = [authUI authViewController];
//    [self presentViewController:authViewController animated:YES completion:nil];
}
Related