Wednesday, 6 July 2016

Adding Firebase to an iOS Project

This week, I made significant progress on my first iOS app, but was surprised to see that the iAd banner I had previously implemented was no longer working.

Of course, anyone who'd been working on iOS and Apple development for longer than me would have realised that Apple discontinued iAd on 30th June 2016 - but since this was all announced back in January, it was old news before I even started looking at iAd!

In the process of implementing Google AdMob as a replacement, Google pushed me quite strongly towards also adding Firebase to my project - which seems like a good idea, for Analytics if nothing else.

The manual installation instructions for Firebase seemed quite simple; just drag-and-drop the appropriate Frameworks into my project, add an obscure Linking parameter, and I should be good to go.  However, this didn't work; once the Frameworks were installed, the project refused to build...
I've certainly got something wrong, but with only limited experience of Xcode, debugging this was proving a challenge.

The simple solution seems to be to use the CocoaPods dependency management to add Firebase instead.  The first few resources I found indicated that this could be easily done; CocoaPods requires Ruby > 2.0.0, which is installed by default on all modern macOS systems.

sudo gem install cocoapods

Welcome to dependency chasing!

  • CocoaPods now requires Ruby > 2.2.0, which is not installed
  • Updating Ruby is best done using RVM, which is not installed
  • The installation instructions for RVM require GPG to verify the signatures
Fortunately, from this point on it was simple; GPGTools provides a nice installer for the Mac, which allowed me to install the latest version of RVM using a simple curl script, which then allowed me to install Ruby 2.2

Once Ruby 2.2 was available, the standard instructions for installing CocoaPods worked fine.

With CocoaPods, it was quite easy to add Firebase to my project, and build succeeded.

Once that was working, it was also very easy to see why my original manual installation of Firebase had failed; the archive provided by Google was missing the FirebaseAnalytics.framework, which includes a lot of the headers needed for successful compilation.

I'm blaming this one on Google!

No comments:

Post a Comment