|
| 1 | +# FirebaseUI for iOS — Phone Auth |
| 2 | + |
| 3 | +You can use Firebase Phone Authentication to sign in a user by sending an SMS message to the user's phone.The user signs in using a one-time code contained in the SMS message. |
| 4 | + |
| 5 | +## Table of Contents |
| 6 | + |
| 7 | +1. [Installation](#installation) |
| 8 | +1. [Integration](#using-firebasephoneui-for-authentication) |
| 9 | +1. [Customization](#customizing) |
| 10 | + |
| 11 | +## Installation |
| 12 | +### Importing FirebaseUI Phone Auth components |
| 13 | +Add the following to your `Podfile`: |
| 14 | +```ruby |
| 15 | + pod 'FirebaseUI/Auth' |
| 16 | + pod 'FirebaseUI/Phone' |
| 17 | +``` |
| 18 | + |
| 19 | +### Configuring sign-in provider |
| 20 | +To use FirebaseUI to authenticate users you first need to configure each provider you want to use in |
| 21 | +their own developer app settings. Please read the *Before you begin* section of the [Firebase |
| 22 | +Phone Auth configuration guides](https://firebase.google.com/docs/auth/ios/phone-auth#before_you_begin). |
| 23 | + |
| 24 | +## Using FirebasePhoneUI for Authentication |
| 25 | + |
| 26 | +### Integration |
| 27 | + |
| 28 | +In order to use Phone Auth you should initialize Phone provider and add it to the list of FUIAuth providers. Please notice that you should use only one instance of Phone Auth providers. It can be retrieved form FUIAuth providers list. |
| 29 | + |
| 30 | +```swift |
| 31 | +// Swift |
| 32 | +import Firebase |
| 33 | +import FirebaseAuthUI |
| 34 | +import FirebasePhoneAuthUI |
| 35 | + |
| 36 | +/* ... */ |
| 37 | + |
| 38 | +FUIAuth.defaultAuthUI()?.delegate = self |
| 39 | +let phoneProvider = FUIPhoneAuth.init(authUI: FUIAuth.defaultAuthUI()!) |
| 40 | +FUIAuth.defaultAuthUI()?.providers = [phoneProvider] |
| 41 | +``` |
| 42 | + |
| 43 | +```objective-c |
| 44 | +// Objective-C |
| 45 | +@import FirebaseAuthUI; // OR #import <FirebaseAuthUI/FirebaseAuthUI.h> |
| 46 | +@import FirebasePhoneAuthUI; // OR #import <FirebasePhoneAuthUI/FUIPhoneAuth.h> |
| 47 | + |
| 48 | +/* ... */ |
| 49 | + |
| 50 | +[FUIAuth defaultAuthUI].delegate = self; // delegate should be retained by you! |
| 51 | +FUIPhoneAuth *phoneProvider = [[FUIPhoneAuth alloc] initWithAuthUI:[FUIAuth defaultAuthUI]]; |
| 52 | +[FUIAuth defaultAuthUI].providers = @[phoneProvider]; |
| 53 | +``` |
| 54 | +
|
| 55 | +### Sign In |
| 56 | +
|
| 57 | +To start the authentication flow: |
| 58 | +
|
| 59 | +```swift |
| 60 | +// Swift |
| 61 | +let phoneProvider = FUIAuth.defaultAuthUI()?.providers.first as! FUIPhoneAuth |
| 62 | +phoneProvider.signIn(withPresenting: currentlyVisibleController, phoneNumber: nil) |
| 63 | +} |
| 64 | +``` |
| 65 | + |
| 66 | +```objective-c |
| 67 | +// Objective-C |
| 68 | +FUIPhoneAuth *phoneProvider = [FUIAuth defaultAuthUI].providers.firstObject; |
| 69 | +[phoneProvider signInWithPresentingViewController:currentlyVisibleController phoneNumber:nil]; |
| 70 | +``` |
| 71 | +
|
| 72 | +## Customizing |
| 73 | +Customizing of Phone Auth is planned to be implemented in 2017 Q4 |
0 commit comments