Firebase Storage for iOS app Feeds and Caching

Firebase Storage for iOS app Feeds and Caching

Firebase Storage
Using Firebase Storage to serve JSON Feeds

Firebase is a great technology which does most of your backend tasks without needing your own server. You also don’t need to write APIs to store and get the data. Firebase provides all the necessary APIs.

It also unifies your efforts if you are developing iOS as well as Android applications in the sense you could use same API’s, Push Notification interface, App Analytics, etc through a single interface.

Serving JSON feeds through firebase helps to save performance of your own server especially if you are expecting huge downloads.

It can be achieved very easily using below mentioned steps

Below code is written in Swift 3.

It is assumed that you have set up Public Read permissions on your Firebase Storage Account.

Below is a screenshot showing how to set Public Read Permissions

Firebase Storage Rules
Firebase Storage Rules

Import FireBase

Create a reference to your Firebase storage

Setting the path for the local file (which will be eventually stored on the local device)

Download the firebase file and store it on the local device

Here we download the file and store it locally so next time the feed gets parsed from the local device rather than downloading it again

Now finally, how to update the local file

Here we get the metadata of the firebase file to check the updated date. We can compare the date with the creation date of the corresponding local file and then decide whether or not to download the firebase file again.


Read more about using Firebase with iOS

Add Google analytics to iOS app

Add Google analytics to iOS app

This shows how to add Google Analytics to your iOS app and not having to use the Firebase Analytics.
1. Login to your Google Analytics Account and create a New Property

  1. On the New Property screen select Mobile app, Google Analytics Services SDK. Type your App Name as shown.

Rest of the settings can be selected based on your requirement. Then click the button Get Tracking ID

  1. Once you get the tracking ID which would be in the format UA-XXXXXXXX-X, click the link for the iOS SDK Getting started guide

  2. As mentioned on the Getting Started guide page, create a pod file using terminal by navigating to your project and typing below command

  1. Open the newly created pod file and add below code just below the line which says # Pods for My iOS App

  1. Run below command

  1. Now open your project as workspace

  2. Click the button GET A CONFIGURATION FILE on the instructions page which will take you to your firebase console

  3. Login and create your Firebase Project if you haven’t created by typing your App name and iOS Bundle ID

10. Now create a file within your project named as GoogleService-info.plist (Do not download the file from Firebase console)

  1. Within Firebase console, open your project and Click on Project settings as shown below. Here you will find all the necessary details to fill the above file related to your project. Tracking code will be on the Google Analytics Account Tracking Info page

  1. Now just go through the rest of the settings as mentioned on the Getting started guide page i.e. creating a bridging header file, adding necessary code in AppDelegate file, etc