目录
此内容是否有帮助?

# iOS SDK Multi-Instance Guide

# I. Introduction of Multi-Example Functions

In iOS SDK version 1.2.0, multiple APPID features have been added. Multiple SDK instances can be created to report data to their respective APPIDs, i.e. multiple APPIDs can be reported.

In iOS SDK version 2.1.0, the feature of lightweight instances is added to support the generation of multiple sub-lightweight instances for the same APPID. The sub-lightweight instances are consistent with the PPID of the parent, but the account information is inconsistent.

If you upgrade the old version (before 1.2.0) SDK to a version after 1.2.0, if there is still unreported data in the local cache of the old version SDK, it will be directly reported to the first instantiated APPID. For users who use only one APPID instance, the data has no impact.

# II. How to Create Multiple SDK Instances

This section describes how to initialize the SDK for iOS SDK after 1.2.0 and how to create multiple SDK instances:


  //initialize
  ThinkingAnalyticsSDK *instance = [ThinkingAnalyticsSDK startWithAppId:APP_ID withUrl:SERVER_URL];

  // SDK can then be used in two ways
  [instance track:@"event_name" properties:eventProperties];
  // [[ThinkingAnalyticsSDK sharedInstanceWithAppid:APP_ID] track:@"event_name" properties:eventProperties];

  // Prior to 1.2.0, or as a single instance, the following SDK can be used
  // [[ThinkingAnalyticsSDK sharedInstance] track:@"event_name" properties:eventProperties];

  //Support for initializing multiple APPID instances
  //ThinkingAnalyticsSDK *instance2 = [ThinkingAnalyticsSDK startWithAppId:APP_ID2 withUrl:SERVER_URL2];

Please note that the APPID of multiple SDK instances must be different, and most of the data between multiple instances is not common. For details, please refer to Section 4 "Data and Settings Sharing between Multiple Instances".

# III. Create A Light Instance

In the iOS SDK version 2.1.0, you can create multiple instances under the same APPID by means of light instances.


  //First create an SDK instance
  ThinkingAnalyticsSDK *instance = [ThinkingAnalyticsSDK startWithAppId:APP_ID withUrl:SERVER_URL];

  //Call createLightInstance to generate a light instance from the example created earlier
  ThinkingAnalyticsSDK *lightInstance  = [instance createLightInstance];

  [lightInstance login:@"123ABCabc@thinkingdata.cn"];
  [lightInstance track:@"some_event" properties:eventProperties];

The APPID, reporting address and some settings of the child lightweight instance are the same as those of the parent instance, but other information is not shared. For details, please refer to Section 4, 'Data and Settings Sharing among Multiple Instances'.

# IV. Data Sharing Among Multiple Instances

Most interfaces are called by instance objects, so most data and settings are not shared between multiple APPID instances, parent instances and lightweight instances, but some data and settings will take effect for all instances. The following is a detailed description of whether all data and settings are shared among multiple instances:

  1. Account related information
  • System default generated guest ID #distinct_id: share
  • Call identifyset guest ID #distinct_id: not shared
  • Call loginsetting account ID #account_id: not shared
  1. Event reporting trackand user feature reporting user_set, user_setOnce, user_add, user_delete: not shared
  2. Public properties setSuperPropertiesand dynamic public properties registerDynamicSuperProperties: not shared
  3. Is SDK configuration information shared across multiple instances:
  • Reporting policy related (i.e. reporting interval versus volume of data per batch): shared, determined by project data corresponding to the first instantiated APPID
  • Uploaded network condition setNetworkType: shared
  1. Automatic event acquisition
  • It is recommended to enable automatic collection of events on only one instance
  • Support reporting automatic collection events to multiple APP IDs
  • The setting of automatic collection events can only take effect for a single APPID instance. For details, please refer to the iOS SDK Automatic Collection Guide
  1. Log event timeEvent: not shared