Posts

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

"photoUpload" might not be a great identifier for a URLSessionConfiguration object

In iOS, there isn't much you can do if your app isn't in the foreground. For certain kinds of apps, that makes programming for iOS more challenging than for Android. One thing you can do is schedule an upload while your app is running, and have the upload happen even if you close down your app. Here's one way that almost makes it work:   static var urlSession: URLSession = {     let configuration = URLSessionConfiguration . background (withIdentifier: "photoUpload" )     configuration. sessionSendsLaunchEvents = false     return URLSession (configuration: configuration)    }()   static func startUpload(fileUrl: URL , uploadUrl:  URL ) {        var urlRequest = URLRequest (url: uploadUrl )        urlRequest. setValue ( "image/jpeg" , forHTTPHeaderField: "Content-Type" )       urlRequest. httpMethod = "POST"       urlSession . uploadTask (with: urlRequest, fromFile: fileUrl). resume ()      }

Authenticating with Cloud Functions for Firebase from your iOS Swift app

My "blog" seems to be a random collection of things that I want people to be able to find. So be it! Right now (August 2017) I can't find good documentation about how take an iOS app in which the user is logged into Firebase, and use those credentials to communicate with a Cloud Function for Firebase. Here's how, inspired partly by the authorized-https-endpoint  example function, and partly by a helpful post by Kato Richardson . Unfortunately this method doesn't work to access the database directly, as in Kato's post. The "authorization" header set below doesn't appear to be read for that. Nobody should copy/paste this code and use it unmodified. It handles errors poorly.     static func getJson( url: URL ,           completion callback: (( _ json: [ String : Any ]?, _ error: String ?) -> Void )?) {       Auth . auth (). currentUser !. getIDToken (completion: { (token, error) in         if let error = error {           c

No, programming competitions don't produce bad engineers

A couple of times a year, someone finds  this video by Peter Norvig and makes a blog post saying "Being good at programming competitions correlates negatively with being good on the job," and people jump to all kinds of conclusions about it. What it's actually about In the mid-'00s, a team at Google built a machine learning model to figure out what features of Google employees predicted good performance at Google. Each feature ended up with a positive or negative score, and the one for participation in programming competitions was negative. What can we conclude from that? Not much. Hire the highest jumpers I just bought a minor league basketball team, so I need players. It's expensive to pay scouts; so I'll use scouts to hire only half my team. Jumping high is important, so I'll look at a list of the highest jumpers in the U.S. and hire them. High jumpers suck On my team, the people who can jump the highest are going to be the worst players.
Putting this here for lack of a better place: after I installed Ad-Aware on Windows, I started having problems with Protractor tests, where ChromeDriver wouldn't start (Firefox and IE were fine). I got this error: C:\Users\Bartholomew\Documents\dev\orders\node_modules\selenium-webdriver\error.js:27     super(opt_error);     ^ SessionNotCreatedError: session not created exception from disconnected: Unable to receive message from renderer   (Session info: chrome=51.0.2704.106)   (Driver info: chromedriver=2.22.397933 (1cab651507b88dec79b2b2a22d1943c01833cc1b),platform=Windows NT 10.0.10586 x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 1.97 seconds I failed to remember that I'd recently installed Ad-Aware, so it took me a long time to debug this problem. I got approximately nowhere; it appeared nobody else had had the same problem. Hopefully this will turn up in someone's search results and be useful