我想将这个答案的功劳归因于这个
帖子,因为他指出了
FireBase 远程配置 和
A/B 测试。
由于提问者的要求,我将解释实现它所涉及的步骤。
服务器上的配置
访问https://console.firebase.google.com/并使用您的Google账户登录。
选择创建项目并点击iOS
输入应用程序ID和昵称,然后点击注册应用程序
它将显示一个链接到GoogleService-Info.plist下载,然后将其拖放到项目中
选择下一步
它将向您显示运行您的应用程序以验证安装,您可以选择跳过此步骤
从首页选择远程配置
选择添加变量并输入您选择的变量名称,但我输入ABTestVariationType并留下值为空,然后选择发布更改
从侧边栏选择A/B测试,然后单击创建实验,然后选择远程配置
在即将出现的弹出窗口中,输入您选择的名称,我输入为A/B测试POC,输入一些描述(可选)
在目标用户中选择您的应用程序ID,在目标用户百分比中选择100%,然后单击下一步,然后它将显示变体部分
在变体部分中,将有一个名为控制组的常规类别,默认加载50%,以及一个填充了50%和空框的变体框,您可以在其中输入任何名称,但我会输入变体2。现在点击添加参数8次,现在您可以看到每个变体都有10%,并命名所有变体,我会将变体3、变体4命名为变体10。
在相同的变体部分中,从远程配置中单击添加参数
现在,您可以看到每个变体参数旁边出现一个框。您可以输入唯一值以识别每种口味。我会为第一个变体输入值1,为第二个变体输入值2,依此类推,最后一个变体为值10,然后单击下一步
然后目标部分出现,您可以选择其中之一,但我会选择保留(15+)天,然后单击审核,再单击开始实验,在出现的提示中再次选择开始
在应用中集成
Add the following pods in your project
pod 'Firebase/Core'
pod 'Firebase/RemoteConfig'
Drag and drop the GoogleService-Info.plist that was downloaded during the server configuration
Initiate the firebase with following boiler-plate code
@import Firebase;
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions(NSDictionary *)launchOptions
{
[FIRApp configure];
return YES;
}
4. 在您的项目中,有一个名为
RcValues的类,它是另一个样板代码。
#import "RcValues.h"
@import Firebase;
@implementation RcValues
+(RcValues *)sharedInstance
{
static RcValues *sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [[RcValues alloc] init];
});
return sharedInstance;
}
-(id)init{
self=[super init];
if(self)
{
[self AcivateDebugMode];
[self LoadDefaultValues];
[self FetchCloudValues];
}
return self;
}
-(void)LoadDefaultValues
{
[FIRRemoteConfig.remoteConfigsetDefaults:
@{@"appPrimaryColor":@"#FBB03B"}];
}
-(void)FetchCloudValues
{
NSTimeInterval fetchInterval=0;
[FIRRemoteConfig.remoteConfigfetchWithExpirationDuration:
fetchInterval completionHandler:^(FIRRemoteConfigFetchStatus
status, NSError *_Nullable error)
{
NSLog(@"error:%@",error);
[FIRRemoteConfig.remoteConfig activateFetched];
}];
}
-(void)AcivateDebugMode{
FIRRemoteConfig.remoteConfig.configSettings=debugSettings;
FIRRemoteConfigSettings *config = [[FIRRemoteConfigSettings alloc] initWithDeveloperModeEnabled:YES];
FIRRemoteConfig.remoteConfig.configSettings=config;
}
@end
在AppDelegate的didFinishLaunchingWithOptions方法中调用该类。
RcValues *Obj=[RcValues sharedInstance]
这将下载 ABtesting 的 keyvalue。
6. 使用下面的代码从 Firebase 获取 AB 测试密钥到您的应用程序中。
self.flavourNumber.text=[FIRRemoteConfig.remoteConfig
configValueForKey:@"ABTestVariationType"].stringValue
基于关键值,您可以按照您的意愿显示不同的用户界面。
Firebase会负责发送正确的值,您无需自己将用户分组。
P.S
请按以下教程获取更详细的信息,这只是一个摘要。我将在有空时尝试总结或添加更多图片以便于理解。如果可能的话,我会尝试在GitHub上添加示例项目,并在此处链接。
Firebase iOS AB测试教程
Firebase远程配置iOS教程