Posts

Showing posts from 2018

Authenticating phone numbers with Firebase on iOS

I wanted to have a way for my users to associate a phone number with their user profiles in my Firebase-based iOS app. Here's what I came up with. Bear in mind that this is something that worked, but isn't engineered beautifully; at some point I'll give presentLogin a better name and make it static. The basic approach was to use FirebaseUI to do all the authentication. I needed to keep the user logged in to the current app, though, so I instantiated an app with a different "name" using the same settings. I had a hiccup when I used a FUIAuthDelegate that wasn't also a UIViewController: authUI.delegate is a weak reference, so when my AuthGetPhoneNumber object went out of scope, it got garbage collected and my callbacks never got called. The "avoidGarbageCollection" family of functions at the bottom of the class is how I avoided that; I wonder whether Swift has a better built-in way of handling this. I'm mildly proud of how I record the phone