Firebase Remote Config iOS Setup Guide
Important references:
- Refer to the
firebase-basicsskills, particularly those for iOS setup, before proceeding. - Refer to the
xcode-project-setupskills.
Project and App Setup
Use the firebase-tools CLI to set up the project if necessary.
- Find Bundle ID: Read the Xcode project to find the iOS bundle ID. Check
the
PRODUCT_BUNDLE_IDENTIFIERvalue in the.pbxprojfile or theInfo.plistfile. - Create Firebase Project: If no project exists, create one:
npx -y firebase-tools@latest projects:create <project-id> --display-name="My Awesome App" - Create Firebase App: Register the iOS app with the discovered bundle ID:
npx -y firebase-tools@latest apps:create IOS <display-name> --bundle-id=<bundle-id> - Link the GoogleService-Info.plist file: Use the script in the
xcode-project-setupskill to obtain the config and link.
Add Swift Package Dependencies
Install the Remote Config and Analytics SDKs using the Swift package manager.
Install the FirebaseRemoteConfig and FirebaseAnalytics packages from the
https://github.com/firebase/firebase-ios-sdk.git
repository.
Initialize Firebase in App Code
Modify the application's entry point to initialize Firebase. Refer to the iOS setup reference in the firebase-basics skill.
Follow up Steps
The following steps cover the essential patterns for using Remote Config effectively in your iOS app.
Set In-App Defaults
Define default values so your app behaves as intended before it connects to the backend. Create a property list file (e.g., RemoteConfigDefaults.plist):
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>welcome_message</key>
<string>Welcome to the app!</string>
<key>is_feature_enabled</key>
<false/>
</dict>
</plist>Then, initialize the SDK and set the defaults:
import FirebaseRemoteConfig
let remoteConfig = RemoteConfig.remoteConfig()
remoteConfig.setDefaults(fromPlist: "RemoteConfigDefaults")Fetch and Activate Values
To retrieve values from the cloud and apply them to your app:
remoteConfig.fetchAndActivate { (status, error) in
if status == .successFetchedFromRemote || status == .successUsingPreFetchedData {
print("Config fetched and activated!")
} else {
print("Config not fetched")
}
// Access a value
let message = remoteConfig.configValue(forKey: "welcome_message").stringValue
}