Firebase Remote Config Tutorial for iOS

In this tutorial, you’ll learn how to make changes to your iOS app immediately without resubmitting to the App Store. By Fabrizio Brancati.

Leave a rating/review
Download materials
Save for later
Share
Update note: Fabrizio Brancati updated this tutorial for iOS 14.2, Swift 5.3, and Firebase 7.x. Todd Kerpelman wrote the original.

Remember that time you published your app, and it was perfect in every way? You never had to touch another line of code because you managed to get everything just right the first time around?

Me neither.

Being a successful app developer usually means making frequent changes to your app. Sometimes, these changes are new features or bug fixes. But sometimes, the most impactful updates are one-line changes to your code, like adjusting a line of text or nerfing a powerful unit in a tower defense game.

Although these kinds of changes are easy to make, publishing them is still a multi-day process. Wouldn’t it be nice if you could make some of these tweaks without having to go through that whole process?

Firebase Remote Config gives you that power. Throughout this tutorial, you’ll use the PlanetTour sample app to learn how to change text, colors, and other behavior without having to publish new builds! You’ll be able to avoid going through the App Store approval process and deliver small changes to your users instantly. Once you’ve mastered simple tweaks, you’ll learn the more powerful feature of delivering different sets of content to different users.

Prerequisites: This tutorial assumes you have some familiarity with, and an installation of, CocoaPods. If you don’t, please check out our CocoaPods tutorial.

Getting Started

Get started by downloading the materials via the Download Materials link at the top or bottom of this tutorial. Unzip and run the starter project app. Swipe to view different planets and tap each to get some (mostly accurate) extra information.

PlanetTour Start

The app you’ve just downloaded is made by PlanetTour Apps, Inc., where things are going great until, one day, Greg from marketing decides PlanetTour should switch to a green color scheme in celebration of Earth Day.

It’s an easy enough fix — if you look in AppConstants.swift, there’s an appPrimaryColor property you can change, which will affect many of your text label colors. Pushing this change out to your users would involve publishing a new build, submitting it to the App Store, getting it approved, and then hoping all your users download it before Earth Day. You’d have to do the whole process again to revert the change once Earth Day was over.

Wouldn’t it be nice if you could just alter these values … from the cloud?

Installing the Remote Config Library

To get started using Remote Config instead of the hard-coded values currently in AppConstants, you need to create a project in the Firebase Console, associate it with the PlanetTour app, and then install the Firebase Remote Config library.

Creating a Project in Firebase Console

The first step is to create a project. To do this:

  1. Open firebase.google.com/console
  2. Click Add project.
  3. Name your project PlanetTour, then click Continue:
    Name your project screen
  4. Next, be sure that Enable Google Analytics for this project is selected, then click Continue:
    Google Analytics for your Firebase project
  5. Next, select an existing Google Analytics account or create one, then click Create project:
    Configure Google Analytics screen

You have created your project! Now, you must associate it with the PlanetTour app.

Associating the Project with the PlanetTour App

After creating your project, you’ll be redirected to your app’s homepage. To connect the project with the app:

Get started by adding Firebase to your app

Register your app

Download config file

Run your app to verify installation

  1. Add an iOS app by clicking the iOS logo:
  2. Get started by adding Firebase to your app

  3. Add the bundle ID of your project — com.raywenderlich.PlanetTour — and the app nickname — PlanetTour — but leave the App Store ID field blank, and then click Register App:
  4. Register your app

  5. Click the Download button to download a GoogleServices-info.plist file:
  6. Download config file

  7. At this point, your browser will download a GoogleServices-info.plist file for you. Drag this file into your Xcode project, as shown in the screenshot above from the Firebase instructions. Be sure to select Copy Items if Needed.
  8. Click Next through the remaining few steps in the setup wizard. Don’t worry: You’ll walk through those instructions next. Finish the wizard by clicking with Continue to Console:
  9. Run your app to verify installation

  10. Switch back to Xcode and close the PlanetTour project.

You’re almost there now! But you still have to install the Remote Config Library.

Installing the Firebase Remote Config Library

You need to enable your app to find new values on the internet. To do this:

Next, add the following implementation to application(_:didFinishLaunchingWithOptions:) before the return statement:

This method reviews the libraries you already have installed and initializes them, using the constants provided to your project when you added the GoogleServices-info.plist file. The Remote Config library now knows where to look on the internet to find new values.

  1. Open a Terminal window and navigate to your project. The easiest way to do this is to type “cd ” (with a space at the end) and wait to submit the command. Then open a Finder window and locate the folder containing your Xcode project. Drag and drop the folder from Finder into Terminal. The location of the folder will be filled into the command in Terminal. Press Return on your keyboard in Terminal to submit the command.
  2. Type pod init and press Return to create a basic Podfile in the project folder.
  3. Open the Podfile using your favorite text editor, and replace its contents with the following, then save it:
    target 'PlanetTour' do
      # Comment this line if you're not using Swift 
      # and don't want to use dynamic frameworks
      use_frameworks!
      platform :ios, '12.0'
    
      # Pods for PlanetTour
      pod 'Firebase/Core', '~> 7.0.0'
      pod 'Firebase/RemoteConfig', '~> 7.0.0'
    
      # Remove Xcode 12 warnings
      post_install do |installer|
        installer.pods_project.targets.each do |target|
          target.build_configurations.each do |config|
            config.build_settings.delete 'IPHONEOS_DEPLOYMENT_TARGET'
          end
        end
      end
    end
    
  4. Run pod install in Terminal.
  5. Open the new PlanetTour.xcworkspace with Xcode. (Note: You want the workspace, not the project.) The workspace incorporates the code from CocoaPods specified in your Podfile.
  6. Note: A simple way to ensure you open the correct file is to enter the following command in Terminal:
    xed .
    
  7. Use the Project navigator to open AppDelegate.swift. Add the following below import UIKit:
    import Firebase
    

    Next, add the following implementation to application(_:didFinishLaunchingWithOptions:) before the return statement:

    FirebaseApp.configure()
    

    This method reviews the libraries you already have installed and initializes them, using the constants provided to your project when you added the GoogleServices-info.plist file. The Remote Config library now knows where to look on the internet to find new values.

Note: A simple way to ensure you open the correct file is to enter the following command in Terminal:
xed .
target 'PlanetTour' do
  # Comment this line if you're not using Swift 
  # and don't want to use dynamic frameworks
  use_frameworks!
  platform :ios, '12.0'

  # Pods for PlanetTour
  pod 'Firebase/Core', '~> 7.0.0'
  pod 'Firebase/RemoteConfig', '~> 7.0.0'

  # Remove Xcode 12 warnings
  post_install do |installer|
    installer.pods_project.targets.each do |target|
      target.build_configurations.each do |config|
        config.build_settings.delete 'IPHONEOS_DEPLOYMENT_TARGET'
      end
    end
  end
end
xed .
import Firebase
FirebaseApp.configure()

Build and run your app, again. The app should look as it did previously except that you’ll see debug information in your console output that you didn’t see before.

PlanetTour screen

Congratulations! You’ve installed Remote Config! Now, you can use it in the rest of this tutorial.