This document describes the basic operations for using the QuickTracking iOS (A/B Testing) SDK.
SDK basic information
File name | Version number | md5 | File size |
QuickTracking ABTest SDK | 1.4.3 Update Log: iOS/macOS SDK Update Log | 11b8a9f58b18a18a1590c2e571c0d7ba | 1.7 MB |
1. Code integration details
The A/B Testing SDK depends on the iOS SDK v1.6.0 or later. Before you can use the A/B Testing SDK, you must integrate and initialize the QuickTracking Analytics SDK. For more information, see Import and configure the SDK.
2. Programmatic experiments
2.1 Integrate and initialize the SDK
First, initialize the QuickTracking Analytics SDK synchronously. After the QuickTracking Analytics SDK is initialized, you can initialize the QuickTracking A/B Testing SDK. When you initialize the QuickTracking A/B Testing SDK, you must pass the URL for requesting diversion experiments. You can obtain this URL from your operations personnel.
Integrate the QuickTracking SDK
CocoaPods method (recommended)
Add the following content to your Podfile:
pod 'QTABTest'Open the terminal and switch to the project directory.
Run pod install or pod update.
If you cannot pull the latest version, run pod repo update and then run pod install or pod update.
Manual integration
Contact the QuickTracking product operations team to obtain the offline QTABTest SDK package: QTABTestSDK.xcframework.
Project configuration
Add the
QTABTestSDK.xcframeworkfile to your application project.

SDK initialization
/** Initializes the QuickTracking ABTest iOS SDK.
@param configOptions The initialization configurations.
*/
+ (void)startWithConfigOptions:(QTABTestConfigOptions *)configOptions;The QTABTestConfigOptions class
#import <Foundation/Foundation.h>
typedef void (^OnABTestPropertyChangedBlock)(NSArray * _Nonnull result);
NS_ASSUME_NONNULL_BEGIN
@interface QTABTestConfigOptions : NSObject
/// The URL to get experiment results.
@property (nonatomic, copy) NSURL *baseURL;
/// The interval at which the SDK actively polls for the latest experiment results. Unit: seconds. The default value is 10 minutes. The minimum value is 10 seconds and the maximum value is 30 minutes. If the value is outside this range, the default value is used.
@property (nonatomic) NSTimeInterval updateInterval;
/// The callback for changes in locally cached experiment result data.
@property (nonatomic, copy) OnABTestPropertyChangedBlock onABTestPropertyChangedBlock;
- (instancetype)init NS_UNAVAILABLE;
/** The initialization method.
@param urlString The URL string.
@return An instance object.
*/
- (instancetype)initWithURL:(NSString *)urlString NS_DESIGNATED_INITIALIZER;
@end
NS_ASSUME_NONNULL_ENDExample:
#import <QTABTestSDK/QTABTestSDK.h>
QTABTestConfigOptions *configOptions = [[QTABTestConfigOptions alloc] initWithURL:@"your_data_collection_endpoint/abtest_results?appkey=xxxxx"];
// Actively poll for the latest experiment results every 30 seconds.
configOptions.updateInterval = 30;
// Callback for changes in locally cached experiment result data.
// Method 1: Set in the initialization configuration.
configOptions.onABTestPropertyChangedBlock = ^(NSArray * _Nonnull result) {
NSLog(@"---------result: %@",result);
/** Example of returned result data
[
{"gid": xxx, "expid": xxx,},
{"gid": xxx, "expid": xxx,},
...
]
**/
};
[QTABTest startWithConfigOptions:configOptions];Enable logging
/// Specifies whether to print the SDK log information in the console.
/// @param enable Specifies whether to enable or disable debug log output. YES: enable. NO: disable. The default value is NO.
+ (void)setLogEnabled:(BOOL)enable;Example:
[QTABTest setLogEnabled:YES];2.1.1 Set the callback API for data changes in the local cache
API name | Scenario description |
setAbPropertyChangedBlock | The developer sets a listener callback for data changes in the locally cached experiment results of the A/B SDK. |
Usage example
#import <QTABTestSDK/QTABTestSDK.h>
// Callback for changes in locally cached experiment result data.
// Method 2: Set by the developer.
[[QTABTest sharedInstance] setAbPropertyChangedBlock:^(NSArray * _Nonnull result) {
NSLog(@"---------result: %@",result);
/** Example of returned result data
[
{"gid": xxx, "expid": xxx,},
{"gid": xxx, "expid": xxx,},
...
]
**/
}];2.2 Get experiment variables
After you initialize the QuickTracking ABTest SDK, you can use an API to retrieve the variable values for a specific experiment. You can use one of the following three policies to retrieve experiment variable values:
fetchABTestFromCache: Reads data from the local cache. If the cache is empty, the default value is returned.
fetchABTestFromServer: Ignores the local cache and retrieves data from the server-side.
fetchABTestFromCacheThenServer: Reads data from the local cache first. If the cache is empty, it retrieves data from the server-side.
Scenario descriptions
API name | Scenario description |
fetchABTestFromCache | If you have high requirements for query performance, use the fetchABTestFromCache API to get variable values only from the local cache. The disadvantage is that you cannot hit the latest experiment results in time. |
fetchABTestFromServer | If you are conducting a time slice experiment and have high requirements for timeliness, use the fetchABTestFromServer API to get experiment variable values. The disadvantage is that there may be some network latency. |
fetchABTestFromCacheThenServer | By default, use this API. It balances query performance and timeliness. This API prioritizes getting variable values from the local cache. If the local cache does not hit a result, it queries the A/B testing server for the latest data. |
2.3 API introduction
fetchABTestFromCache
// Reads the local cache to get the experiment. If the cache does not exist, the default value is used.
/// @param paramName The name of the experiment parameter.
/// @param defaultValue The default result.
/// @return The experiment value.
- (nullable id)fetchABTestFromCacheWithParamName:(NSString*)paramName
defaultValue:(id)defaultValue;Request parameters
Parameter | Type | Description | Notes |
paramName | NSString | Experiment parameter name | Required. Must be a non-empty string. |
defaultValue | NSString | BOOL | NSNumber | NSDictionary | Default result value for the experiment parameter | Required. The type must be the same as the current experiment value result type. For example, if the experiment value type for the parameter is NUMBER, the passed defaultValue must also be a number type, and the returned result is also a number type. |
Note: Make sure that you implement the business logic required to handle the default values that are used in the A/B diversion API.
Return value
Parameter | Type | Default | Description | Notes |
<T> T | NSString | BOOL | NSNumber | NSDictionary | nil | Experiment parameter result value | The type of the set experiment result value must be the same as the experiment value type. Otherwise, the SDK considers it an abnormal experiment result. Also, make sure that your business logic properly handles the returned result. |
Usage example
#import "QTABTest.h"
// Request a parameter of the NSString type.
NSString *result = [[QTABTest sharedInstance] fetchABTestFromCacheWithParamName:@"ios_test_string" defaultValue:@"111"];
// Request a parameter of the Boolean type.
BOOL result = [[QTABTest sharedInstance] fetchABTestFromCacheWithParamName:@"ios_test_bool" defaultValue:@(YES)];
// Request a parameter of the Number type.
NSNumber result = [[QTABTest sharedInstance] fetchABTestFromCacheWithParamName:@"ios_test_number" defaultValue:@1];
// Request a parameter of the NSDictionary type.
NSDictionary *dict = @{
@"param1" : @"1"
};
NSDictionary *result = [[QTABTest sharedInstance] fetchABTestFromCacheWithParamName:@"ios_test_json" defaultValue:dict];fetchABTestFromServer
// Ignores the local cache and gets data from the server-side. Asynchronously gets the latest experiment results from the server-side.
/// @param paramName The name of the experiment parameter.
/// @param defaultValue The default result.
/// @param timeoutInterval The timeout period. Unit: seconds.
/// @param completionHandler The callback on the main thread, which returns the experiment result.
- (void)fetchABTestFromServerWithParamName:(NSString*)paramName
defaultValue:(id)defaultValue
timeoutInterval:(NSTimeInterval)timeoutInterval
completionHandler:(void (^)(id _Nullable result))completionHandler;Request parameters
Parameter | Type | Default | Description | Notes |
paramName | NSString | nil | Experiment parameter name | Required. Must be a non-empty string. |
timeoutInterval | NSTimeInterval | 600 | Timeout period for the diversion experiment server-side request | Optional. |
defaultValue | NSString | BOOL | NSNumber | NSDictionary | nil | Default result value for the experiment parameter | Required. The type must be the same as the current experiment value result type. For example, if the experiment value type for the parameter is NUMBER, the passed defaultValue must also be a number type, and the returned result is also a number type. |
<T> T | NSString | BOOL | NSNumber | NSDictionary | nil | Experiment parameter result value | The type of the set experiment result value must be the same as the experiment value type. Otherwise, the SDK considers it an abnormal experiment result. Also, make sure that your business logic properly handles the returned result. |
callback | callback | None | Callback function for the diversion experiment result value | Required. |
Callback description:
typedef void (^QTABCompletionHandler)(id _Nullable result);Return parameters:
Parameter | Type | Default | Description | Notes |
<T> T | NSString | BOOL | NSNumber | NSDictionary | nil | Experiment parameter result value | The type of the set experiment result value must be the same as the experiment value type. Otherwise, the SDK considers it an abnormal experiment result. Also, make sure that your business logic properly handles the returned result. |
Note: Make sure that you implement the business logic required to handle the default values that are used in the A/B diversion API.
Return value
Parameter | Type | Default | Description | Notes |
result | NSString | BOOL | NSNumber | NSDictionary | nil | Experiment parameter result value | The type of the set experiment result value must be the same as the experiment value type. Otherwise, the SDK considers it an abnormal experiment result. Also, make sure that your business logic properly handles the returned result. |
Usage example
NSDictionary *dict = @{
@"param1" : @"1"
};
NSString *paramName = @"ios_test_json";
[[QTABTest sharedInstance] fetchABTestFromServerWithParamName:paramName defaultValue:dict timeoutInterval:10 completionHandler:^(id _Nullable result) {
if (result) {
NSLog(@"======result:%@", result);
}
}];fetchABTestFromCacheThenServer
// Reads the local cache first. If the cache does not exist, it gets data from the server-side.
/// @param paramName The name of the experiment parameter.
/// @param defaultValue The default value.
/// @param timeoutInterval The timeout period. Unit: seconds.
/// @param completionHandler The callback on the main thread, which returns the experiment result.
- (void)fetchABTestFromCacheThenServerWithParamName:(NSString*)paramName
defaultValue:(id)defaultValue
timeoutInterval:(NSTimeInterval)timeoutInterval
completionHandler:(void (^)(id _Nullable result))completionHandler;Request parameters
Parameter | Type | Default | Description | Notes |
paramName | NSString | nil | Experiment parameter name | Required. Must be a non-empty string. |
timeoutInterval | NSTimeInterval | 600 | Timeout period for the diversion experiment server-side request | Optional. |
defaultValue | NSString | BOOL | NSNumber | NSDictionary | nil | Default result value for the experiment parameter | Required. The type must be the same as the current experiment value result type. For example, if the experiment value type for the parameter is NUMBER, the passed defaultValue must also be a number type, and the returned result is also a number type. |
<T> T | NSString | BOOL | NSNumber | NSDictionary | nil | Experiment parameter result value | The type of the set experiment result value must be the same as the experiment value type. Otherwise, the SDK considers it an abnormal experiment result. Also, make sure that your business logic properly handles the returned result. |
callback | callback | None | Callback function for the diversion experiment result value | Required. |
Note: Make sure that you implement the business logic required to handle the default values that are used in the A/B diversion API.
Return value
Parameter | Type | Default | Description | Notes |
result | NSString | BOOL | NSNumber | NSDictionary | Experiment parameter result value | The type of the set experiment result value must be the same as the experiment value type. Otherwise, the SDK considers it an abnormal experiment result. Also, make sure that your business logic properly handles the returned result. |
Usage example
NSString *defaultValue = @"111";
NSString *paramName = @"ios_test_string";
[[QTABTest sharedInstance] fetchABTestFromCacheThenServerWithParamName:paramName defaultValue:defaultValue timeoutInterval:10 completionHandler:^(id _Nullable result) {
if (result) {
NSLog(@"======result:%@", result);
}
}];3. Debug experiments
After you start an experiment:

When logging is enabled, a list of your experiments is printed.
