Posts

Showing posts from 2017

"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.