All Products
Search
Document Center

Quick Tracking:iOS SDK

Last Updated:Oct 14, 2025

Mandatory for using QuickTracking iOS(A/B Testing).

Basic SDK information

File Name

Version number

md5

File Size

QuickTracking ABTest SDK

1.4.1

Update logs: iOS and macOS SDK update logs

d0b53bdb125c5c2a43a8d46a9216f8c6

2.9 MB

1. Integration code details

The A/B Testing SDK depends on iOS SDK V1.6.0 or later. Before you use the SDK, make sure that you have successfully integrated the Quick Tracking Statistics SDK and initialized the SDK. For more information, see Introduction and configuration of the SDK.

2. Programming experiment

2.1 integration and initialization

You must initialize the Quick Tracking SDK in synchronous mode. After you initialize the QuickTracking statistics SDK, initialize the QuickTracking A/B Testing SDK. When you initialize the Quick Tracking A/B Testing SDK, you must specify the URL of the request diversion test. Contact the operation personnel to obtain the URL.

Integrate the QuickTracking SDK

CocoaPods (recommend)

  1. Add in Podfile

    pod 'QTABTest'
  2. Open a terminal and switch to the project directory

  3. Run the pod install or pod update command

  4. If the latest version cannot be pulled, run the pod repo update first, and then run the pod install or pod update

Manual integration

Contact the user of QuickTracking to obtain the QTABTest SDK offline package: QTABTestSDK.xcframework.

Engineering Configuration

  1. Add QTABTestSDK.xcframework files to the application project

image

Initialize the SDK

/**Initialize QuickTracking ABTest iOS SDK
 @ param configOptions Initialize the configuration.
 */
+ (void)startWithConfigOptions:(QTABTestConfigOptions *)configOptions;

QTABTestConfigOptions Class

#import <Foundation/Foundation.h>

typedef void (^OnABTestPropertyChangedBlock)(NSArray * _Nonnull result);

NS_ASSUME_NONNULL_BEGIN

@interface QTABTestConfigOptions : NSObject

/// Obtain the URL of the experiment result.
@property (nonatomic, copy) NSURL *baseURL;

/// The SDK actively polls the latest experiment result gap (unit: seconds). The default value is 10 minutes, the minimum value is 10 seconds, and the maximum value is 30 minutes.
@property (nonatomic) NSTimeInterval updateInterval;

/// The callback for data changes to the local cache experiment results.
@property (nonatomic, copy) OnABTestPropertyChangedBlock onABTestPropertyChangedBlock;

- (instancetype)init NS_UNAVAILABLE;

/**Initialization method
 @ param urlString URL URL
 @ return The instance object.
 */
- (instancetype)initWithURL:(NSString *)urlString NS_DESIGNATED_INITIALIZER;

@end

NS_ASSUME_NONNULL_END

Example:

#import <QTABTestSDK/QTABTestSDK.h>

QTABTestConfigOptions *configOptions = [[QTABTestConfigOptions alloc] initWithURL:@"Your service address /abtest_results?appkey=xxxxx"];
// Poll the latest experiment results every 30 seconds.
configOptions.updateInterval = 30;
// The callback that is fired when the experiment results are cached locally.
// Method 1: Set the initial configuration.
configOptions.onABTestPropertyChangedBlock = ^(NSArray * _Nonnull result) {
    NSLog(@"---------result: %@",result);
    /**Sample response data
        [
          {"gid": xxx, "expid": xxx,}, 
          {"gid": xxx, "expid": xxx,},
          ...
        ]
    **/
};
[QTABTest startWithConfigOptions:configOptions];

Enable logging

/// Set whether to output the SDK log in the console.
/// @param enable Enable /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 local cache

API Name

Scenario description

setAbPropertyChangedBlock

Developers set the AB SDK to locally cache experiment results and listen for callbacks for data changes.

Example
#import <QTABTestSDK/QTABTestSDK.h>

// The callback that is fired when the experiment results are cached locally.
// Method 2: Developer settings
[[QTABTest sharedInstance] setAbPropertyChangedBlock:^(NSArray * _Nonnull result) {
    NSLog(@"---------result: %@",result);
    /**Sample response data
        [
          {"gid": xxx, "expid": xxx,}, 
          {"gid": xxx, "expid": xxx,},
          ...
        ]
    **/
}];

2.2 acquisition of experimental variables

Initialize the QuickTracking ABTest SDK, through the API to obtain a specific test variable value, according to the test variable value of the way, can be divided into the following three strategies:

  • fetchABTestFromCache: Read the local cache. If the cache does not exist, the default value is used.

  • fetchABTestFromServer: Ignore local cache and get data from server

  • fetchABTestFromCacheThenServer: First read the local cache, cache does not exist from the server to obtain data

Scenarios

API Name

Scenario description

fetchABTestFromCache

If you have requirements on query performance, you can use fetchABTestFromCache API to obtain variable values only from the local cache. The disadvantage is that the latest experimental results cannot be hit in time.

fetchABTestFromServer

If you want to perform a time slice rotation experiment and have requirements on the timeliness of the experiment, you can use fetchABTestFromServer API to obtain the experimental variable values. The disadvantage is that there may be a certain network latency.

fetchABTestFromCacheThenServer

By default, we recommend that you use this API to take into account the query performance and timeliness. This API preferentially obtains variable values from the local cache. If the local cache does not hit the result, the latest data of the AB experiment server is queried.

2.3 API introduction

fetchABTestFromCache

// Read the local cache to obtain 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 Experimental value
- (nullable id)fetchABTestFromCacheWithParamName:(NSString*)paramName
                                   defaultValue:(id)defaultValue;
request parameters

Parameters

Type

Meaning

Remarks

paramName

NSString

Experiment Parameter Name

Required parameter. You must set a non-empty string.

defaultValue

NSString | BOOL | NSNumber | NSDictionary

Default result values for experiment parameters

Required parameters, which must be consistent with the current experimental value result type.

If the experiment value corresponding to the parameter is of the NUMBER type, the input defaultValue must also be of the NUMBER type, and the returned result experiment result must also be of the NUMBER type.

Important

Note: Make sure that the default values used in the /B offload interface are processed properly.

Return Result

Parameters

Type

Default Value

Meaning

Remarks

<T> T

NSString | BOOL | NSNumber | NSDictionary

nil

Experimental parameter result value

the specified experiment result value must be of the same type as the experiment value. otherwise, the sdk considers the experiment result as abnormal. At the same time, please note that the results returned by result have made normal business logic judgment in the business.

Usage example
#import "QTABTest.h"

// The request returns the NSString parameter. 
NSString *result = [[QTABTest sharedInstance] fetchABTestFromCacheWithParamName:@"ios_test_string" defaultValue:@"111"];

// The Boolean parameter returned for the request. 
BOOL result = [[QTABTest sharedInstance] fetchABTestFromCacheWithParamName:@"ios_test_bool" defaultValue:@(YES)];

// The number parameter returned by the request. 
NSNumber result = [[QTABTest sharedInstance] fetchABTestFromCacheWithParamName:@"ios_test_number" defaultValue:@1];

// The request returns the NSDictionary parameter.
NSDictionary *dict = @{
    @"param1" : @"1"
    };
NSDictionary *result = [[QTABTest sharedInstance] fetchABTestFromCacheWithParamName:@"ios_test_json" defaultValue:dict];

fetchABTestFromServer

// Obtain the latest experiment results from the server asynchronously, ignoring the local cache.
/// @param paramName The name of the experiment parameter.
/// @param defaultValue The default result.
/// @param timeoutInterval the timeout period. Unit: seconds.
/// @param completionHandler the main thread callback to return the experiment result.
- (void)fetchABTestFromServerWithParamName:(NSString*)paramName
                             defaultValue:(id)defaultValue
                          timeoutInterval:(NSTimeInterval)timeoutInterval
                        completionHandler:(void (^)(id _Nullable result))completionHandler;
request parameters

Parameters

Type

Default Value

Meaning

Remarks

paramName

NSString

nil

Experiment Parameter Name

Required parameter. You must set a non-empty string.

timeoutInterval

NSTimeInterval

600

The server request timeout period of the shunt experiment.

Required parameters

defaultValue

NSString | BOOL | NSNumber | NSDictionary

nil

Default result values for experiment parameters

Required parameters, which must be consistent with the current experimental value result type.

If the experiment value corresponding to the parameter is of the NUMBER type, the input defaultValue must also be of the NUMBER type, and the returned result experiment result must also be of the NUMBER type.

<T> T

NSString | BOOL | NSNumber | NSDictionary

nil

Experimental parameter result value

the specified experiment result value must be of the same type as the experiment value. otherwise, the sdk considers the experiment result as abnormal. At the same time, please note that the results returned by result have made normal business logic judgment in the business.

callback

callback

None

Shunt experiment result value callback function

Required parameters

Callback description:

typedef void (^QTABCompletionHandler)(id _Nullable result);

Return parameters:

Parameters

Type

Default Value

Meaning

Remarks

<T> T

NSString | BOOL | NSNumber | NSDictionary

nil

Experimental parameter result value

the specified experiment result value must be of the same type as the experiment value. otherwise, the sdk considers the experiment result as abnormal. At the same time, please note that the results returned by result have made normal business logic judgment in the business.

Important

Note: Make sure that the default values used in the /B offload interface are processed properly.

Return Result

Parameters

Type

Default Value

Meaning

Remarks

result

NSString | BOOL | NSNumber | NSDictionary

nil

Experimental parameter result value

the specified experiment result value must be of the same type as the experiment value. otherwise, the sdk considers the experiment result as abnormal. At the same time, please note that the results returned by result have made normal business logic judgment in the business.

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

// First read the local cache and obtain data from the server if the cache does not exist.
/// @param paramName The name of the experiment parameter.
/// @param defaultValue The default value.
/// @param timeoutInterval the timeout period. Unit: seconds.
/// @param completionHandler the main thread callback to return the experiment result.
- (void)fetchABTestFromCacheThenServerWithParamName:(NSString*)paramName
                                      defaultValue:(id)defaultValue
                                   timeoutInterval:(NSTimeInterval)timeoutInterval
                                 completionHandler:(void (^)(id _Nullable result))completionHandler;
request parameters

Parameters

Type

Default Value

Meaning

Remarks

paramName

NSString

nil

Experiment Parameter Name

Required parameter. You must set a non-empty string.

timeoutInterval

NSTimeInterval

600

The server request timeout period of the shunt experiment.

Required parameters

defaultValue

NSString | BOOL | NSNumber | NSDictionary

nil

Default result values for experiment parameters

Required parameters, which must be consistent with the current experimental value result type.

If the experiment value corresponding to the parameter is of the NUMBER type, the input default_value must also be of the number type, and the returned result experiment result is also of the number type.

<T> T

NSString | BOOL | NSNumber | NSDictionary

nil

Experimental parameter result value

the specified experiment result value must be of the same type as the experiment value. otherwise, the sdk considers the experiment result as abnormal. At the same time, please note that the results returned by result have made normal business logic judgment in the business.

callback

callback

None

Shunt experiment result value callback function

Required parameters

Important

Note: Make sure that the default values used in the /B offload interface are processed properly.

Return Result

Parameters

Type

Default Value

Meaning

Remarks

result

NSString | BOOL | NSNumber | NSDictionary

Experimental parameter result value

the specified experiment result value must be of the same type as the experiment value. otherwise, the sdk considers the experiment result as abnormal. At the same time, please note that the results returned by result have made normal business logic judgment in the business.

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. Commissioning test

After opening the experiment

image

When log is enabled, the corresponding experiment list will be printed out.

image