UX Optimizer – iOS¶
Remote Config interface¶
Access to UX Optimizer API is possible via the remoteConfig
property in the Repro.h
header file.
Repro.remoteConfig.setDefaults(fromDictionary: ["key1": "v1", "key2": "v2"])
let val = Repro.remoteConfig.value(forKey: "key1").stringValue
Setting Local defaults¶
Three methods are available. It is recommended to call these 3 methods in your application:didFinishLaunchingWithOptions:
before calling Repro.setup()
.
From a dictionary¶
Repro.remoteConfig.setDefaults(fromDictionary: ["key1": "value1", "key2": "value2"])
From a raw Json string¶
Repro.remoteConfig.setDefaults(fromJsonString: "{\"key1\": \"zzz1\", \"key2\": \"zzz2\"}")
From a Json file¶
if let defs: URL = Bundle.main.url(forResource: "remote_config_defaults", withExtension: "json") {
Repro.remoteConfig.setDefaults(fromJsonFile: defs)
}
Access to Remote Config values¶
Single value¶
if let value: String = Repro.remoteConfig.value(forKey: "key1").stringValue {
// ... use value ...
// stringValue will be nil if 'key1' is not found in
// either the remote config or the local fallback
}
Note
The return value of
Repro.remoteConfig.value(forKey: 'key1')
is always an instance ofRPRRemoteConfigValue
and nevernil
.You may also just the subscript shortcut:
Repro.remoteConfig['key1'].stringValue
.
All items with a certain prefix¶
Repro.remoteConfig.allValues(withPrefix: "color")
will return a dictionary of all values of which keys start with color
.
Reset values¶
While in development, you may call Repro.remoteConfig.forceReset() to reset to the initial state. You will have to set local defaults & fetch callbacks again after calling forceReset()
.
Repro.remoteConfig.forceReset()
Fetch & Activate¶
Everytime the app enters foreground, Remote Config values wil be retrieved from the Repro server & automatically activated. Therefore, a fetch callback is not necessary. If you want to control when to apply the fetched values, you can call activateFetched()
. If you want to switch old Remote Config values for new values at a certain point in time after they have been retrieved, setting a callback is recommended.
Only one callback can be set
The callback is not guaranteed to be called.
The timeout is set in whole seconds via a
NSTimeInterval
float like value.If a fetch could not be performed while the app was in foreground, the callback will be deleted and not executed. Therefore, it is recommended to set the callback from
applicationWillEnterForeground:
in yourUIApplicationDelegate
.If you set a callback in
application:willFinishLaunchingWithOptions:
, the callback should be set before a call toRepro.setup()
is made.If the callback is executed, it is guaranteed to be executed on the main thread, so you can safely update UI elements from within the callback.
Without a call to
Repro.setup()
, fetching is not performed and the callback will never be executed.activateFetched()
should be executed after the callback has been executed. From within the callback block is of course also possible. Like in the following example.
fetch example
Repro.remoteConfig.fetch(withTimeout: 3.0) { status in
if status == .success {
print("OLD Remote Config Values: \(Repro.remoteConfig.allValues())")
Repro.remoteConfig.activateFetched()
print("NEW Remote Config Values: \(Repro.remoteConfig.allValues())")
}
}
Please refer to the header file for further limitations on fetching.