アプリ内パラメーター¶
Remote Config インターフェース¶
アプリ内パラメーターの各機能は次のAPIより利用可能です。
[Repro remoteConfig]
Repro.remoteConfig
Repro.getRemoteConfig()
Repro.getRemoteConfig()
ReproCpp::getRemoteConfig()
Repro.RemoteConfig
Repro.remoteConfig
Repro.remoteConfig
Repro.remoteConfig
ローカルのデフォルト値を設定する¶
2つの方法が利用できます。
Dictionary/Map/JSONを利用する¶
// setDefaultsFromDictionary must be executed before [Repro setup].
[[Repro remoteConfig] setDefaultsFromDictionary: @{ @"key1": @"value1", @"key2": @"value2" }];
// setDefaults must be executed before Repro.setup().
Repro.remoteConfig.setDefaults(fromDictionary: ["key1": "value1", "key2": "value2"]);
// setDefaultsFromMap must be executed before Repro.setup().
HashMap<String, Object> values = new HashMap<>();
values.put("key1", "value1");
values.put("key2", "value2");
Repro.getRemoteConfig().setDefaultsFromMap(values);
// setDefaultsFromMap must be executed before Repro.setup().
val values: HashMap<String, Any> = HashMap()
values["key1"] = "value1"
values["key2"] = "value2"
Repro.getRemoteConfig().setDefaultsFromMap(values)
// setDefaultsFromMap must be executed before ReproCpp::setup().
std::map<std::string, std::string> defaults;
defaults["key1"] = "value1";
defaults["key2"] = "value2";
ReproCpp::getRemoteConfig().setDefaultsFromMap(defaults);
// SetDefaultsFromMap must be executed before Repro.Setup().
var dic = new Dictionary<string, object>();
dic.Add("key1", "value1");
dic.Add("key2", "value2");
Repro.RemoteConfig.SetDefaultsFromMap(dic);
// setDefaultsFromJson must be executed before Repro.setup().
Repro.remoteConfig.setDefaultsFromJson(
{"key1": "value1", "key2": "value2"},
function(message) {
// success callback
},
function(message) {
// error callback
}
);
Repro.remoteConfig.setDefaultsFromDictionary({
key1: "value1",
key2: "value2",
});
Repro.remoteConfig.setDefaultsFromMap({
'key1' : 'value1',
'key2' : 'value2',
});
Json文字列を利用する¶
// setDefaultsFromJsonString must be executed before [Repro setup].
[[Repro remoteConfig] setDefaultsFromJsonString: @"{\"key1\": \"value1\", \"key2\": \"value2\"}"];
// setDefaults must be executed before Repro.setup().
Repro.remoteConfig.setDefaults(fromJsonString: "{\"key1\": \"value1\", \"key2\": \"value2\"}")
// setDefaultsFromJsonString must be executed before Repro.setup().
Repro.getRemoteConfig().setDefaultsFromJsonString("{\"key1\": \"value1\", \"key2\": \"value2\"}");
// setDefaultsFromJsonString must be executed before Repro.setup().
Repro.getRemoteConfig().setDefaultsFromJsonString("{\"key1\": \"value1\", \"key2\": \"value2\"}")
// setDefaultsFromJsonString must be executed before ReproCpp::setup().
ReproCpp::getRemoteConfig().setDefaultsFromJsonString("{\"key1\": \"value1\", \"key2\": \"value2\"}");
// SetDefaultsFromJsonString must be executed before Repro.Setup().
Repro.RemoteConfig.SetDefaultsFromJsonString("{\"key1\": \"value1\", \"key2\": \"value2\"}");
// setDefaultsFromJsonString must be executed before Repro.setup().
Repro.remoteConfig.setDefaultsFromJsonString(
"{\"key1\": \"value1\", \"key2\": \"value2\"}",
function(message) {
// success callback
},
function(message) {
// error callback
}
);
Repro.remoteConfig.setDefaultsFromJsonString("{\"key1\": \"value1\", \"key2\": \"value2\"}");
await Repro.remoteConfig.setDefaultsFromJsonString("{\"key1\": \"value1\", \"key2\": \"value2\"}");
Remote Config の値にアクセスする¶
特定の値にアクセスする¶
特定の値を取得する場合はキーを完全一致で指定します。
// The return value of [[Repro remoteConfig] valueForKey: "key1"] is always an RPRRemoteConfigValue instance and will never be nil.
NSString *string = [[Repro remoteConfig] valueForKey: @"key1"].stringValue;
// The return value of Repro.remoteConfig.value(forKey: 'key1') is always an RPRRemoteConfigValue instance and will never be nil.
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
}
// The return value of Repro.getRemoteConfig().get('key1') is always an RPRRemoteConfigValue instance and will never be nil.
// If no value exists for a given key, the RemoteConfigValue's asString() returns null, but toString() returns an empty string.
String value = Repro.getRemoteConfig().get("key1").asString();
// The return value of Repro.getRemoteConfig().get('key1') is always an RPRRemoteConfigValue instance and will never be nil.
// If no value exists for a given key, the RemoteConfigValue's asString() returns null, but toString() returns an empty string.
val value = Repro.getRemoteConfig().get("key1").asString()
// The return value of ReproCpp::getRemoteConfig().get("key1") is always an RPRRemoteConfigValue instance and will never be nil.
const char* value = ReproCpp::getRemoteConfig().get("key1").getStringValue();
// The return value of Repro.RemoteConfig.Get("key1") is always an RPRRemoteConfigValue instance and will never be nil.
string value = Repro.RemoteConfig.Get("key1").AsString();
// If no value exists for the given key, the value returned by the success callback will be null.
Repro.remoteConfig.getValue(
"key1",
function(value) {
const stringValue = value;
// success callback
},
function(message) {
// error callback
}
);
// If no value exists for the given key, the value returned by the callback will be null.
Repro.remoteConfig.getValue("key1", (value) => {
let string = value.toString();
});
// The return value of Repro.remoteConfig.get('key1') is always an RPRRemoteConfigValue instance and will never be nil.
var remoteConfigValue = await Repro.remoteConfig.get('key1');
var stringValue = remoteConfigValue.asString();
Remote Config全体¶
全ての値を取得する場合は allValues
を使用します。
// Returns a Dictionary with all values.
NSDictionary<NSString *, RPRRemoteConfigValue *> *values = [[Repro remoteConfig] allValues]
// Returns a Dictionary with all values.
var values: Dictionary<NSString, RPRRemoteConfigValue> = Repro.remoteConfig.allValues()
// Returns a Map with all values.
Map<String, RemoteConfigValue> values = Repro.getRemoteConfig().getAllValues();
// Returns a Map with all values.
Map<String, RemoteConfigValue> values = Repro.getRemoteConfig().getAllValues()
// Returns a Map with all values.
std::map<std::string, RemoteConfigValue*> = ReproCpp::getRemoteConfig().getAllValues();
// Returns a Dictionary with all values.
Dictionary<string, RemoteConfigValue> value = Repro.RemoteConfig.GetAllValues();
// Returns an associative array with all values.
Repro.remoteConfig.getAllValues(
function(values) {
// success callback
}
);
// Returns an associative array with all values.
Repro.remoteConfig.getAllValues((values) => {
console.log(values);
});
// Returns a Map with all values.
var values = await Repro.remoteConfig.getAllValues();
プリフィックスを指定してアクセスする¶
特定のキーワードに先頭がマッチするキーの値すべてを取得する場合はプリフィックスを指定します。
// Returns a Dictionary with key values starting with "color".
NSDictionary<NSString *, RPRRemoteConfigValue *> *values = [[Repro remoteConfig] allValuesWithPrefix: @"color"]
// Returns a Dictionary with key values starting with "color".
var values: Dictionary<NSString, RPRRemoteConfigValue> = Repro.remoteConfig.allValues(withPrefix: "color")
// Returns a Map with key values starting with "color".
Map<String, RemoteConfigValue> values = Repro.getRemoteConfig().getAllValuesWithPrefix("color");
// Returns a Map with key values starting with "color".
Map<String, RemoteConfigValue> values = Repro.getRemoteConfig().getAllValuesWithPrefix("color")
// Returns a Map with key values starting with "color".
std::map<std::string, RemoteConfigValue*> = ReproCpp::getRemoteConfig().getAllValuesWithPrefix("color");
// Returns a Dictionary with key values starting with "color".
Dictionary<string, RemoteConfigValue> value = Repro.RemoteConfig.GetAllValuesWithPrefix("color");
// Returns an associative array with key values starting with "color".
Repro.remoteConfig.getAllValuesWithPrefix("color",
function(values) {
// success callback
}
);
// Returns an associative array with key values starting with "color".
Repro.remoteConfig.getAllValuesWithPrefix("color", (values) => {
console.log(values);
});
// Returns a Map with key values starting with "color".
var values = await Repro.remoteConfig.getAllValuesWithPrefix("color");
値をリセットする¶
Remote Configオブジェクトを初期状態に戻したい場合は forceReset()
を呼び出してください。 forceReset()
の実行後は、ローカルのデフォルト値やコールバックを再びセットする必要があります。
[[Repro remoteConfig] forceReset]
Repro.remoteConfig.forceReset()
Repro.getRemoteConfig().forceReset()
Repro.getRemoteConfig().forceReset()
ReproCpp::getRemoteConfig().forceReset()
Repro.RemoteConfig.ForceReset()
Repro.remoteConfig.forceReset()
Repro.remoteConfig.forceReset()
await Repro.remoteConfig.forceReset()
Fetch と Activate¶
Remote Configの値はアプリがフォアグラウンドに遷移するたびに自動的にReproのサーバーから取得し直されるため、fetchコールバックは必ず必要というわけではありません。取得した設定値を反映する場合は activateFetched()
を呼び出してください。
古いRemote Configの値を新しく取得された値で置き換えるタイミングを制御したい場合はfetchコールバックを利用することを推奨します。
- 登録できるコールバックは1つです。
- コールバックは必ず実行されることを保証するものではありません。
- コールバックの中でUI上の要素を更新することも可能です。
fetch()
を実行しても、タイムアウトまたはRepro.setup()
が呼び出されるまで実際の処理およびコールバックが実行されることはありません。activateFetched()
はコールバックの実行完了後に呼び出してください。コールバックのブロックの中から呼び出すことも可能です。
fetch の例
// The timeout is specified in seconds using NSTimeInterval.
[[Repro remoteConfig] fetchWithTimeout:3.0 completionHandler:^(RPRRemoteConfigFetchStatus fetchStatus) {
if (fetchStatus == RPRRemoteConfigFetchStatusSuccess) {
NSDictionary<NSString *, RPRRemoteConfigValue *> *oldValues = [[Repro remoteConfig] allValues];
for (id key in [oldValues keyEnumerator]) {
NSLog(@"OLD Remote Config Key:%@ Value:%@", key, [oldValues valueForKey:key]);
}
[[Repro remoteConfig] activateFetched];
NSDictionary<NSString *, RPRRemoteConfigValue *> *newValues = [[Repro remoteConfig] allValues];
for (id key in [newValues keyEnumerator]) {
NSLog(@"OLD Remote Config Key:%@ Value:%@", key, [newValues valueForKey:key]);
}
}
}];
// The timeout is specified in seconds using NSTimeInterval.
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())")
}
}
// The timeout is specified in milliseconds.
Repro.getRemoteConfig().fetch(3000, new RemoteConfigListener() {
@Override
public void onCompletion(FetchStatus status) {
if (status == FetchStatus.SUCCESS) {
Log.d("remote_config", "BEFORE " + Repro.getRemoteConfig().getAllValues().toString());
Repro.getRemoteConfig().activateFetched();
Log.d("remote_config", "AFTER " + Repro.getRemoteConfig().getAllValues().toString());
}
}
});
// The timeout is specified in milliseconds.
Repro.getRemoteConfig().fetch(3000) { status ->
if (status == FetchStatus.SUCCESS) {
Log.d("remote_config", "BEFORE " + Repro.getRemoteConfig().allValues.toString())
Repro.getRemoteConfig().activateFetched()
Log.d("remote_config", "AFTER " + Repro.getRemoteConfig().allValues.toString())
}
}
// The timeout is specified in seconds.
ReproCpp::getRemoteConfig().fetch(3, [](ReproCpp::RemoteConfig::FetchStatus status) {
if (status == ReproCpp::RemoteConfig::FetchStatusSuccess) {
log("fetch result: FetchStatusSuccess");
ReproCpp::getRemoteConfig().activateFetched();
}
});
// The timeout is specified in milliseconds.
Repro.RemoteConfig.Fetch(3000, (status) =>
{
if (status == Repro.FetchStatus.Success)
{
var str = string.Join(", ", Repro.RemoteConfig.GetAllValues().Select(elem => elem.Key + " => " + elem.Value.ToString()).ToArray());
Debug.Log("RemoteConfig Values(Before ActivateFetched): " + str);
Repro.RemoteConfig.ActivateFetched();
str = string.Join(", ", Repro.RemoteConfig.GetAllValues().Select(elem => elem.Key + " => " + elem.Value.ToString()).ToArray());
Debug.Log("RemoteConfig Values(After ActivateFetched): " + str);
}
});
// The timeout is specified in milliseconds.
Repro.remoteConfig.fetch(3000, function(status) {
// success callback
if (status == Repro.remoteConfig.FetchStatus.Success) {
Repro.remoteConfig.getAllValues((values) => {
console.log(values);
Repro.remoteConfig.activateFetched(function(message) {
// success callback
Repro.remoteConfig.getAllValues((values) => {
console.log(values);
});
}, function(message) {
// error callback
});
});
} else if (status == Repro.remoteConfig.FetchStatus.AlreadyFetched) {
}
}, function(status) {
// error callback
});
// The timeout is specified in milliseconds.
Repro.remoteConfig.fetch(3000, (status) => {
if (status == Repro.remoteConfig.FETCH_STATUS.REMOTE_CONFIG_SUCCESS) {
Repro.remoteConfig.getAllValues((values) => {
console.log(values);
Repro.remoteConfig.activateFetched();
Repro.remoteConfig.getAllValues((values) => {
console.log(values);
});
});
} else if (status == Repro.remoteConfig.FETCH_STATUS.REMOTE_CONFIG_TIMEOUT_REACHED) {
} else if (status == Repro.remoteConfig.FETCH_STATUS.REMOTE_CONFIG_ALREADY_FETCHED) {
}
});
// The timeout is specified in milliseconds.
await Repro.remoteConfig.fetch(3000, (result) {
if (result == FetchStatus.success) {
var values = await Repro.remoteConfig.getAllValues();
for (var key in values.keys) {
debugPrint('[old RemoteConfig] $key: ${values[key]}');
}
await Repro.remoteConfig.activateFetched();
values = await Repro.remoteConfig.getAllValues();
for (var key in values.keys) {
debugPrint('[new RemoteConfig] $key: ${values[key]}');
}
}
});