Third party remote configuration provider integration is currently in private beta and will be available in the next major release of Appfigurate.
Using Appfigurate remote properties instead of Firebase APIs directly allows for the following:
locally change Firebase remote configuration without affecting your entire customer base.
compile time type safety - Appfigurate remote properties are typed, Firebase remote configuration is not.
avoids hardcoding duplicated flag names throughout your app.
deleting a remote configuration property from Firebase Console won't affect existing apps, they'll continue to use the default value provided in the reset method.
We assume you already have Appfigurate Library and Firebase integrated into your app with the following example remote properties created in the Firebase Console:
Add remote properties into your Configuration subclass
Update your configuration subclass to include your remote configuration properties. Provide default values for the properties in the overridden reset method. See also Supported property types.
Swift Configuration example
import Foundation
import AppfigurateLibrary
@objcMembers class MyConfiguration: APLConfiguration {
...
@RemoteBoolProperty(remoteKey: "alwaysDarkMode", description: "Force dark mode to be always set")
var alwaysDarkMode: Bool
@RemoteStringPropertyEdit(remoteKey: "appTitle", description: "Title of application")
var appTitle: String
@RemoteIntPropertyEdit(remoteKey: "bookingDuration", description: "Duration (days) for reservation bookings")
var bookingDuration: Int
@RemoteDoublePropertyEdit(remoteKey: "fontSize", description: "Size of font throughout app")
var fontSize: Double
...
override func reset() {
alwaysDarkMode = false
appTitle = "Holiday finder"
bookingDuration = 30
fontSize = 13.0
}
...
}
Appfigurate.fetchRemoteConfiguration((remoteKey, propertyType, defaultValue) -> {
return switch (propertyType) {
case RemotePropertyTypeString -> this.remoteConfig.getString(remoteKey);
case RemotePropertyTypeBoolean -> this.remoteConfig.getBoolean(remoteKey);
case RemotePropertyTypeInt -> this.remoteConfig.getLong(remoteKey);
case RemotePropertyTypeDouble -> this.remoteConfig.getDouble(remoteKey);
};
});
Apply default values to Firebase
Apply default values to Firebase using the values you set in the reset method of your configuration subclass. The default values are used by Firebase when the remote configuration has not yet been received.
The APLConfiguration class has a method remoteDefaults which provides a Dictionary of all the remote configuration property default values that were set in your overridden reset method.
Swift example
FirebaseApp.configure()
self.remoteConfig = RemoteConfig.remoteConfig()
...
// add the following line
self.remoteConfig.setDefaults(APLConfiguration.shared().remoteDefaults())
The APLConfiguration class has a method remoteDefaults which provides a NSDictionary* of all the remote configuration property default values that were set in your overridden reset method.
Objective-C example
[FIRApp configure];
self.remoteConfig = [FIRRemoteConfig remoteConfig];
...
// add the following line
[self.remoteConfig setDefaults: [[APLConfiguration sharedConfiguration] remoteDefaults]];
The nz.co.electricbolt.appfiguratelibrary.Configuration class has a method remoteDefaults which provides a HashMap<String,Object> of all the remote configuration property default values that were set in your overridden reset method.
Kotlin example
FirebaseApp.initializeApp(this)
this.remoteConfig = FirebaseRemoteConfig.getInstance()
...
// add the following line
this.remoteConfig.setDefaultsAsync(Configuration.sharedConfiguration().remoteDefaults())
The nz.co.electricbolt.appfiguratelibrary.Configuration class has a method remoteDefaults which provides a HashMap<String,Object> of all the remote configuration property default values that were set in your overridden reset method.
Java example
FirebaseApp.initializeApp(this)
this.remoteConfig = FirebaseRemoteConfig.getInstance()
...
// add the following line
this.remoteConfig.setDefaultsAsync(Configuration.sharedConfiguration().remoteDefaults());
Notify Appfigurate Library when Firebase has received remote configuration values
We need to tell Appfigurate Library that Firebase has received remote configuration, so that it can keep your Configuration subclass remote properties in sync.
Add a call to APLFlushRemoteConfiguration in any existing Firebase Remote Config activate(completion:) blocks (inside fetch(completionHandler:) and optionally addOnConfigUpdateListener(remoteConfigUpdateCompletion:).
Swift example
self.remoteConfig.fetch { status, error in
if status == .success {
self.remoteConfig.activate { changed, error in
...
APLFlushRemoteConfiguration() // add this line
}
}
}
Add a call to APLFlushRemoteConfiguration in any existing Firebase Remote Config activateWithCompletion: blocks (inside fetchWithCompletionHandler: and optionally addOnConfigUpdateListener:).
Add a call to Appfigurate.flushRemoteConfiguration in your existing Firebase Remote Config fetchAndActivate block:
Kotlin fetch and activate example
this.remoteConfig.fetchAndActivate().addOnCompleteListener(this) { task ->
if (task.isSuccessful()) {
...
Appfigurate.flushRemoteConfiguration() // add this line
}
}
If you are optionally using Firebase Remote Config real time updates add a call to Appfigurate.flushRemoteConfiguration in your existing addOnConfigUpdateListener block:
Kotlin real time update example
this.remoteConfig.addOnConfigUpdateListener(object : ConfigUpdateListener {
override fun onUpdate(configUpdate: ConfigUpdate) {
FirebaseRemoteConfig.getInstance().activate().addOnCompleteListener {
...
Appfigurate.flushRemoteConfiguration() // add this line
}
}
...
})
Add a call to Appfigurate.flushRemoteConfiguration in your existing Firebase Remote Config fetchAndActivate block:
Java fetch and activate example
this.remoteConfig.fetchAndActivate().addOnCompleteListener(this, task -> {
if (task.isSuccessful()) {
...
Appfigurate.flushRemoteConfiguration(); // add this line
}
});
If you are optionally using Firebase Remote Config real time updates add a call to Appfigurate.flushRemoteConfiguration in your existing addOnConfigUpdateListener block:
Java real time update example
this.remoteConfig.addOnConfigUpdateListener(new ConfigUpdateListener() {
@Override public void onUpdate(ConfigUpdate configUpdate) {
this.remoteConfig.activate().addOnCompleteListener(task -> {
if (task.isSuccessful()) {
...
Appfigurate.flushRemoteConfiguration(); // add this line
}
});
}
...
});
Best practice and usage
Replace all calls to Firebase Remote Config configValue(forKey:):
if remoteConfig.configValue(forKey: "alwaysDarkMode").boolValue {
...
with the following:
if (APLConfiguration.shared() as! MyConfiguration).alwaysDarkMode {
...
Replace all calls to Firebase Remote Config configValueForKey:
if ([remoteConfig configValueForKey: @"alwaysDarkMode"].boolValue]) {
...
with the following:
if (((MyConfiguration*) [APLConfiguration sharedConfiguration]).alwaysDarkMode) {
...
Replace all calls to Firebase Remote Config getBoolean(), getLong(), getDouble(), getString()
if (this.remoteConfig.getBoolean("alwaysDarkMode")) {
...
with the following:
if (((MyConfiguration) Configuration.sharedConfiguration()).alwaysDarkMode) {
...