iOS

Integrated Requirement

Compliance Notice

The privacy policy of apps that integrate the TDBehavior module should be updated based on our Privacy Agreement with the following additional information:

(1) Function Description: To identify machine behavior fraud risks, the SDK needs to obtain relevant behavior information from you or your end users.

(2) Necessary Personal Information: Touch, scroll, swipe, screen edge swipe, scale behavior information; input behavior information (input type, number of times, input speed, input time); application foreground/background behavior information; browsing page names and dwell time behavior information; device orientation behavior information; gyroscope sensor behavior information; accelerometer sensor behavior information; mouse behavior information (web); keyboard behavior information (web)

(3) Other Optional Personal Information: None


1.SDK Integration

CocoaPods

  • Added pod 'TrustDecisionBehavior', '1.4.2' in the corresponding target in the Podfile
  • Execute the pod install --repo-update command in the folder where the Podfile is located. (M1 series mac computers need to execute arch -x86_64 pod install --repo-update command)

2.Call behavior collect methods to get payload

Behavior collect methods are used to obtain user behavior data. The interface definition is as follows:

typedef struct _TDBehaviorResultStruct{    
    // Return code, 0 represents success    
    const NSInteger code;    
    // Behavior collect data    
    char* const payload;    
    // Error message when failed    
    char* const msg;
}TDBehaviorResultStruct;

/*** TDBehavior start, start behavior collect, write collected data into SDK internal container
*/
void (*start)(void);    

/*** TDBehavior stop, end behavior collect, stop writing collected data into SDK internal container and clear the data in SDK internal container;
*/
void (*stop)(void);

/*** TDBehavior collect, return behavior collect result, if data exists in SDK internal container, it will return success code == 0, and clear the data in SDK internal container;
* If no data exists in SDK internal container, it will return code == 104 error code
*/
TDBehaviorResultStruct (*collect)(void);

Sample Code

⚠️⚠️⚠️ Ensure that there is user behavior after calling start in the business interface, such as text input, click, swipe, etc. Otherwise, calling collect will return a 104 error code, indicating that no behavior data was collected;

    TDMobRiskManager_t *manager = [TDMobRiskManager sharedManager];    
    // When entering business interface, call start method to perform behavior collect, for example when entering login interface    
    manager->start();    
    ...    
    // When calling business interface, call collect method to get behavior collect data, for example when clicking login button    
    TDBehaviorResultStruct resultStruct = manager->collect();    
    NSInteger code = resultStruct.code;    
    char* msg = resultStruct.msg;    
    char* payload = resultStruct.payload;    
    if (code == 0){        
        NSLog(@"Get behavior collect result successfully, payload:%s",payload);    
    }else{        
        NSLog(@"Get behavior collect result failed, code:%ld,msg:%s",code,msg);    
    }    
    ...    
    // When leaving business interface, call stop method to end behavior collect, for example when leaving login interface    
    manager->stop();
    let manager = TDMobRiskManager.sharedManager()    
    // When entering business interface, call start method to perform behavior collect, for example when entering login interface    
    manager?.pointee.start();    
    ...    
    // When calling business interface, call collect method to get behavior collect data, for example when clicking login button    
    let resultStruct = manager?.pointee.collect()    
    let code = resultStruct!.code    
    let msg = resultStruct!.msg    
    let payload = resultStruct!.payload            
    if code == 0 {       
        print("Get behavior collect result successfully, payload:\(String(cString: payload!))")     
    } else {       
        print("Get behavior collect result failed, code:\(code),msg:\(String(cString: msg!))")     
    }    
    ...    
    // When leaving business interface, call stop method to end behavior collect, for example when leaving login interface    
    manager?.pointee.stop();

Specify input fields that do not require collected

Set the attribute accessibilityIdentifier including "TDBehaviorExInput" in UITextField、UITextView . After this setting, the text input events of UITextField、UITextView will no longer be collected

		// will not collect UITextField text input
    UITextField *textField = [[UITextField alloc]init];
    textField.accessibilityIdentifier = @"otherKey,TDBehaviorExInput";
    
    // will not collect UITextView text input
    UITextView *textView = [[UITextView alloc]init];
    textView.accessibilityIdentifier = @"otherKey,TDBehaviorExInput";

3.Return Codes

Error CodeDescriptionSolution
0SuccessNo action needed
100initWithOptions not calledinitWithOptions not called, need to call initWithOptions
101Network authentication result not returned due to low network speedThrow an error to the user: "Network failure, please check the network and try again", guiding the user to call the collect method again
102Network error in authentication interface due to system reasons, such as no network connectionThrow an error to the user: "Network failure, please check the network and try again", guiding the user to call the collect method again
103Authentication interface returns status code is not 200Check if partner parameters are correct. If still fails, provide error message resultStruct.msg to our operations team to confirm if parameters are correct and within validity period
104No data in SDK internal containerThere is no valid collect data,Please Ensure that there is user behavior after calling start in the business interface, such as text input, click, swipe, etc!
109No data in SDK internal containerThere is no valid collect data,Switches are all NO,Please contact TrustDecision!
110No data in SDK internal containerThere is no valid collect data,Please call the start method first!