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.
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Contents
Firebase Remote Config Tutorial for iOS
30 mins
- Getting Started
- Installing the Remote Config Library
- Creating a Project in Firebase Console
- Associating the Project with the PlanetTour App
- Installing the Firebase Remote Config Library
- How Remote Config Works
- Using Remote Config
- Fetching Values From the Cloud
- Running Your Code
- Using Remote Config Values
- Updating Values From the Cloud
- Changing Your App’s Look and Feel
- Addressing the Timing of New Values
- Hooking Up a Loading Screen
- Hook Up the Rest of Your App
- Adding Further Changes to Your App
- Bringing Back Pluto
- Conditions to the Rescue!
- Where to Go From Here?
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.
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.
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:
- Open firebase.google.com/console
- Click Add project.
- Name your project PlanetTour, then click Continue:
- Next, be sure that Enable Google Analytics for this project is selected, then click Continue:
- Next, select an existing Google Analytics account or create one, then click Create project:
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:
- Add an iOS app by clicking the iOS logo:
- 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:
- Click the Download button to download a GoogleServices-info.plist file:
- 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.
- 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:
- 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.
- 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.
- Type
pod init
and press Return to create a basic Podfile in the project folder. - 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
- Run pod install in Terminal.
- 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.
- 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 thereturn
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.
xed .
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.
Congratulations! You’ve installed Remote Config! Now, you can use it in the rest of this tutorial.