Skip to content

SDK Initialization

This article covers the content related to iOS SDK initialization and runtime capabilities.

Basic Configuration

-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
    // SDK FTMobileConfig settings
     // Local environment deployment, Datakit deployment
     //FTMobileConfig *config = [[FTMobileConfig alloc]initWithDatakitUrl:datakitUrl];
     // Public DataWay deployment
    FTMobileConfig *config = [[FTMobileConfig alloc]initWithDatawayUrl:datawayUrl clientToken:clientToken];
    //config.enableSDKDebugLog = YES;              //debug mode
    config.compressIntakeRequests = YES;
    //Start SDK
    [FTMobileAgent startWithConfigOptions:config];

   //...
    return YES;
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
     // SDK FTMobileConfig settings
       // Local environment deployment, Datakit deployment
       //let config = FTMobileConfig(datakitUrl: url)
       // Public DataWay deployment
     let config = FTMobileConfig(datawayUrl: datawayUrl, clientToken: clientToken)
     //config.enableSDKDebugLog = true              //debug mode
     config.compressIntakeRequests = true           //Upload data compression
     FTMobileAgent.start(withConfigOptions: config)
     //...
     return true
}
Property Type Required Meaning
datakitUrl NSString Yes Local environment deployment (Datakit) upload URL address, example: http://10.0.0.1:9529, default port is 9529, the device installing the SDK must be able to access this address. Note: Choose one between datakitUrl and datawayUrl configuration
datawayUrl NSString Yes Public DataWay upload URL address, obtained from the [RUM] application, example: https://open.dataway.url, the device installing the SDK must be able to access this address. Note: Choose one between datakitUrl and datawayUrl configuration
clientToken NSString Yes Authentication token, must be used together with datawayUrl
enableSDKDebugLog BOOL No Set whether to allow log printing. Default is NO
env NSString No Set the collection environment. Default is prod, supports customization, can also be set via the -setEnvWithType: method using the provided FTEnv enumeration
service NSString No Set the name of the associated business or service. Affects the service field data in Log and RUM. Default: df_rum_ios
globalContext NSDictionary No Add custom tags. For addition rules, please refer to here
groupIdentifiers NSArray No Array of AppGroups Identifiers corresponding to Widget Extensions to be collected. If Widget Extensions data collection is enabled, App Groups must be set up, and the Identifier must be configured in this property
autoSync BOOL No Whether to automatically sync collected data to the server. Default is YES. When set to NO, use [[FTMobileAgent sharedInstance] flushSyncData] to manage data synchronization manually
syncPageSize int No Set the number of entries per sync request. Range [5,). Note: A larger number of request entries means data synchronization consumes more computing resources. Default is 10
syncSleepTime int No Set the sync interval time. Range [0,5000], default is not set
enableDataIntegerCompatible BOOL No Recommended to enable when coexistence with web data is required. This configuration handles web data type storage compatibility issues
compressIntakeRequests BOOL No Deflate compression for upload synchronization data. Supported in SDK version 1.5.6 and above. Default is off
enableLimitWithDbSize BOOL No Enable the function to limit total cache size using DB. Note: After enabling, FTLoggerConfig.logCacheLimitCount and FTRUMConfig.rumCacheLimitCount will become invalid. Supported in SDK version 1.5.8 and above
dbCacheLimit long No DB cache limit size. Range [30MB,). Default is 100MB, unit is byte. Supported in SDK version 1.5.8 and above
dbDiscardType FTDBCacheDiscard No Set data discard rules in the database. Default is FTDBDiscard. FTDBDiscard discards appended data when data count exceeds the maximum; FTDBDiscardOldest discards old data when data exceeds the maximum. Supported in SDK version 1.5.8 and above
dataModifier FTDataModifier No Modify individual fields. Supported in SDK version 1.5.16 and above. For usage examples, see Data Collection Desensitization
lineDataModifier FTLineDataModifier No Modify single data entries. Supported in SDK version 1.5.16 and above. For usage examples, see Data Collection Desensitization
remoteConfiguration BOOL No Whether to enable remote configuration for data collection. Default is not enabled. When enabled, SDK initialization or application hot start triggers data updates. Supported in SDK version 1.5.17 and above. Datakit version requirement >=1.60 or using public DataWay
remoteConfigMiniUpdateInterval int No Set the minimum update interval for remote dynamic configuration, unit is seconds, default is 12 hours. Supported in SDK version 1.5.17 and above
remoteConfigFetchCompletionBlock FTRemoteConfigFetchCompletionBlock No Remote configuration result callback, used to receive fetch results and support custom adjustment of configuration models. Supported in SDK version 1.5.19 and above. For usage examples, see here

User Binding and Unbinding

Use FTMobileAgent to bind user information and unbind the current user.

/// Bind user information. This method can be called after successful user login to bind user information.
///
/// - Parameters:
///   - Id:  User Id
///   - userName: User name (optional)
///   - userEmail: User email (optional)
///   - extra: Extra user information (optional)
- (void)bindUserWithUserID:(NSString *)Id userName:(nullable NSString *)userName userEmail:(nullable NSString *)userEmail extra:(nullable NSDictionary *)extra;

/// Unbind the current user. This method can be called after user logout to unbind user information.
- (void)unbindUser;
/// Bind user information. This method can be called after successful user login to bind user information.
///
/// - Parameters:
///   - Id:  User Id
///   - userName: User name (optional)
///   - userEmail: User email (optional)
///   - extra: Extra user information (optional)
open func bindUser(withUserID Id: String, userName: String?, userEmail: String?, extra: [AnyHashable : Any]?)

/// Unbind the current user. This method can be called after user logout to unbind user information.
open func unbindUser()

For extra addition rule precautions, please refer to here.

Runtime Capabilities

Shutting Down the SDK

When using FTMobileAgent to shut down the SDK, be sure to call it in the main thread, otherwise thread safety issues may arise. If dynamically changing SDK configuration, shut down first to avoid generating erroneous data.

+ (void)shutDown;
open class func shutDown()

Clearing SDK Cache Data

Use FTMobileAgent to clear unreported cache data.

+ (void)clearAllData;
open class func clearAllData()

Manually Syncing Data

Use FTMobileAgent to manually sync data.

Data synchronization needs to be managed manually only when FTMobileConfig.autoSync = NO.

- (void)flushSyncData;
func flushSyncData()

Manually Syncing Dynamic Configuration

Dynamic configuration related capabilities have been separated into Dynamic Configuration.