Configo让您可以Granular地控制特性部署和配置回滚。您可以选择哪些段和用户百分比的可见性更新,然后在任何时间增加或减少受影响的用户数量。
Configo将控制权交还给移动团队,使他们能够快速迭代,保持用户体验,并自信地部署。Facebook、Uber、Lyft、Dropbox等许多顶级移动公司已开始使用这些技术为用户提供更好的体验。那么,您的团队呢?
如果您正在使用CocoaPods,请将以下行添加到Podfile
中:
pod "ConfigoSDK", "~> 0.5"
或者,您可以将ConfigoSDK手动添加到您的Xcode项目中。
将以下框架添加到项目的依赖中。这可以在Xcode中从目标的“通用”配置标签下的“链接框架和库”中轻松完成。
SystemConfiguration.framework
CoreTelephony.framework
为了确保ConfigoSDK代码正确加载,在目标的“构建设置”选项卡中添加以下“其他连接器标志”
-ObjC
-all_load
在您的应用程序代理中添加以下导入
#import <ConfigoSDK/ConfigoSDK.h>
在您的application:didFinishLaunchingWithOptions:
方法中添加以下行,以及您的API密钥和开发密钥(您的密钥可以在仪表板中找到)
//OPTIONAL: set the log level
[Configo setLogLevel: CFGLogLevelNone];
[Configo initWithDevKey: @"YOUR_DEV_KEY" appId: @"YOUR_APP_ID"];
可选地,初始化时可以传递一个代码块(例如callback
),该代码块将在加载过程完成后执行
[Configo initWithDevKey: @"YOUR_DEV_KEY" appId: @"YOUR_APP_ID" callback: ^(NSError *err, NSDictionary *config, NSDictionary *features) {
if(err) {
NSLog(@"Failed to load config");
} else {
NSLog(@"The config was loaded: %@, features list: %@", config, features);
}
}];
NOTE: The initialization should be called only once in the lifetime of the app. It has no effect on any consecutive calls.
除非设置自定义ID和属性,否则所有用户都将作为匿名用户跟踪。
匿名用户可以根据他们的设备属性进行切片
使用以下方法可以识别和分段用户以进行定向配置
传递一个用户标识符,例如电子邮件或用户名(我们建议使用唯一值)
[[Configo sharedInstance] setCustomUserId: @"[email protected]"];
传递用户上下文,可以提供更多关于用户的具体信息,并更精确地定位用户,有两种方式:传递一个NSDictionary
[[Configo sharedInstance] setUserContext: @{@"key1" : @"value1", @"key2": @"value2"}];
逐个设置每个属性(在整个应用中的不同类中)
[[Configo sharedInstance] setUserContextValue: @"value1" forKey: @"key1"];
[[Configo sharedInstance] setUserContextValue: @"value2" forKey: @"key2"];
在userContext
中设置的值必须与JSON兼容(《Apple 文档》)
NSDictionary
或NSArray
(所有对象也必须与JSON兼容)NSString
NSNumber
(非 NaN 或无穷大)NSNull
配置是Configo.io的核心,获取它很简单
[[Configo sharedInstance] configValueForKeyPath: @"configKey" fallbackValue: @"fallbackString"];
NOTE: The fallback value will be returned if an error was encountered or the configuration was not found.
配置以JSON文档的形式存储,并由SDK作为NSDictionary
集合检索。
可以使用点符号和括号访问配置值,例如:在以下形式的JSON中
{
"object": {
"array": [1,2,3]
}
}
可以像这样访问数组中的第二个值:
[[Configo sharedInstance] configValueForKeyPath: @"object.array[1]" fallbackValue: nil];
或者,可以直接通过调用rawConfig
来访问配置的NSDictionary
。
可以这样检查特性标志:
[[Configo sharedInstance] featureFlagForKey: @"cool_feature" fallback: YES];
NOTE: The fallback BOOL will be returned if an error occurred or the feature was not found.
可以使用featuresDictionary
检索当前用户激活的所有特性的完整列表。
Configo会在应用启动时以及通过推送机制与仪表板保持同步,关注任何需要同步的本地更改并相应更新。
有时需要手动刷新配置(可选的callback
)
[[Configo sharedInstance] pullConfig: ^(NSError *err, NSDictionary *config, NSDictionary *features) {
//Code for handling feature list/configuration update
}];
NOTE: The callback set here will only be executed once, when that specific call was made. It will have no effect on the callback set using the `setCallback:` method.
配置在应用每次打开时都会更新和加载,以避免运行时的一致性问题。在以下情况下,配置将在运行时更新:
callback
的pullConfig:
。dynamicallyRefreshValues
为YES
。forceRefreshValues
。可以使用几种方法检索Configo的操作状态
每次配置更新时都会触发一个NSNotification。
userInfo
广播ConfigoConfigurationLoadCompleteNotification
:ConfigoNotificationUserInfoRawConfigKey
和ConfigoNotificationUserInfoFeaturesDictionaryKey
,其中包含配置和特性列表。userInfo
广播ConfigoConfigurationLoadErrorNotification
,错误信息在下键中:ConfigoNotificationUserInfoErrorKey
。使用Objective-C blocks
是响应事件执行代码的方便方式。Configo期望所有blocks都必须是CFGCallback
类型,其定义如下
typedef void(^CFGCallback)(NSError *error, NSDictionary *rawConfig, NSDictionary *featuresList);
可以在初始化时设置回调:+ initWithDevKey:appId:callback:
或者可以用setCallback:
方法在任何时候设置。这将替换初始化时设置的回调。
如果手动触发配置刷新,也可以设置一个可选的回调pullConfig:
。这将设置一个"临时"回调,只在手动刷新完成后调用一次。这不会影响在初始化时通过setCallback:
设置或设置的"主要"回调。
NOTE: the "main" callback will be executed as well (if set).
Configo 还有一个名为 state 的属性,可以存储以下任意值:
//There is no config available. CFGConfigNotAvailable //The config was loaded from local storage (possibly outdated). CFGConfigLoadedFromStorage //The config is being loaded from the server. If there is an old, local config - it is still avaiable to use. CFGConfigLoadingInProgress //The config is has being loaded from the server and is ready for use. Might not be active if dynamicallyRefreshValues is false. CFGConfigLoadedFromServer //An error was encountered when loading the config from the server (Possibly no config is available). CFGConfigFailedLoadingFromServer