RMTConfig 0.3.1

RMTConfig 0.3.1

测试已测试
Lang语言 Obj-CObjective C
许可证 MIT
发布最新版本2016年4月

kaiinui 维护。



RMTConfig 0.3.1

  • 作者:
  • kaiinui

RemoteConfig

使用 Google 表格服务器的 iOS 简单远程配置。

[RMTConfig startWithURL:@"https://docs.google.com/spreadsheets/d/1NanRTook1EeXpfIbVNR-tmGSo9h-2LSsdxJQE3n7NYM/pub?gid=0&single=true&output=csv"];

// Then,

RMTString(@"SomeKey", @"SomeDefault");
  // => @"SomeValue" from retrieved configuration

RMTInt(@"SomeNotFoundKey", 2);
  // => 2 from specified default value

// It caches retrieved value and refreshes them when calling every `- startWithURL:`.

1. 设置

-application:didFinishLaunchingWithOptions: 中指定获取并初始化 RMTConfig 的 URL。检索到的值存储并在 NSUserDefaults 中缓存。

[RMTConfig startWithURL:@"https://docs.google.com/spreadsheets/d/1NanRTook1EeXpfIbVNR-tmGSo9h-2LSsdxJQE3n7NYM/pub?gid=0&single=true&output=csv"];

2. 获取值

您可以使用简单的静态函数获取值。当 RMTConfig 尚未检索到 URL 时,它们返回给定的默认值。2.对于密钥的值不存在。

RMTString(@"SomeKey", @"SomeDefault"); // => @"SomeValue" from retrieved configuration

RMTInt(@"SomeNotFoundKey", 2); // => 2 from specified default value 

RMTBool(@"FooBar", NO); // => YES from retrieved configuration

您可以使用它们与 if 语句一起使用,以更具编程性地进行操作。

if (RMTBool(@"ShouldDoSomething", NO)) {
    DoSomething();
}

这允许您在不更新应用程序的情况下切换功能或进行某些测试。太棒了!

3. 编辑值

电子表格的格式很简单。将密钥放在第一列,将值放在第二列。这避免了以 $ 开头的密钥。

您应该从电子表格中获取并指定 .csv URL。要获取 .csv URL,请点击 文件 -> 发布到网络 然后将格式选择下拉到以下内容:

然后您将获得以下 URL。

https://docs.google.com/spreadsheets/d/1NanRTook1EeXpfIbVNR-tmGSo9h-2LSsdxJQE3n7NYM/pub?output=csv

4. 调试

出于调试目的,您可以通过调用简单的 API 来强制返回值。

// This method force `RMTString()` or related methods to return "ForcedValue"
// Do nothing while production build.
[RMTConfig debug_forceValueForKey:@"SomeKey" withString:@"ForcedValue"];

RMTString(@"SomeKey");
  // => @"ForcedValue"

[RMTConfig debug_forceValueForKey:@"SomeBoolKey" withBool:YES];
RMTBool(@"SomeBoolKey", NO); // => YES!

为了帮助调试,在 DEBUG 期间,RMTConfig 会发出一些 NSLog

(可选) 带上您自己的 CSV

您可以使用您自己的 .csv URL。格式如下。

SomeKey, SomeValue
FooBar, 2
TheAnswerOfEveryThing, 42

使用

pod "RMTConfig"

作者

kaiinui (https://kaiinui.com/, https://twitter.com/_kaiinui)