iOS

Requirement

Environment

ItemsDescription
Supported System VersionsiOS 9.0 and above
Supported Architecturesarmv7, arm64, x86_64

Integrate

Install(CocoaPods)

  • Add pod 'TrustDecisionPro', '5.3.2.4' to the target in the Podfile
  • Execute the pod install --repo-update command in the folder where the Podfile is located. (M series mac computers need to execute arch -x86_64 pod install --repo-updatecommand)

Install(Swift Package Manager)

  1. Open your Xcode project
  2. Select File -> Add Package Dependencies...
  3. Enter the repository URL:
https://github.com/trustdecision/trustdevice-pro-ios.git
  1. Set Dependency Rule to Exact Version
  2. Enter version:
5.3.2-4
  1. Select your app target in Add to Target
  2. Click Add Package

Project Configuration

Add -ObjC to the host app target:

  1. Select TARGETS -> your app target
  2. Select Build Settings
  3. Search for Other Linker Flags
  4. Add:
-ObjC

Initialization

Cautions

  • Ensure that it is initialized after the user agrees to the privacy agreement.

Import Header File

#import <TDMobRisk/TDMobRisk.h>
import TDMobRisk

Definition

void (*initWithOptions)(NSDictionary *options);

Get device information

Cautions

  • Call getDeviceInfo after initWithOptions

Definition

void (*getDeviceInfo)(TDDeviceInfoCallback callback);

Best Practices

  1. Call initialization at entry of the application
- (void)initDeviceManagerSDK {
  TDDeviceManager_t *manager = [TDDeviceManager sharedManager];
  NSMutableDictionary *options = [NSMutableDictionary dictionary];
  
  /*************************** Required ***************************/
  // get from our customer platform
  [options setValue:@"[Your partner]" forKey:@"partner"];
  // get from our customer platform
  [options setValue:@"[Your appKey]" forKey:@"appKey"];
  // Data center, Refer to All configuration
  [options setValue:@"[Your data center]" forKey:@"country"];

  manager->initWithOptions(options);
}
func initDeviceManagerSDK() {
  let manager = TDDeviceManager.sharedManager()
  var options = Dictionary<String, Any>()
  
/*************************** Required ***************************/
  // get from our customer platform
  options.updateValue("[Your partner]", forKey: "partner")
  // get from our customer platform
  options.updateValue("[Your appKey]", forKey: "appKey")
 // Country code, Refer to All configuration
  options.updateValue("[Your country code]", forKey: "country")

  manager.pointee.initWithOptions(options)
}
  1. Obtain device information at the actual business node
    TDDeviceManager_t *manager = [TDDeviceManager sharedManager];
    manager->getDeviceInfo(^(TDDeviceResponse response){
        int code = response.apiStatus.code;
        // Char type strings must be converted to String type in multi-threaded situations, otherwise they will be released during thread switching
        if(code == 0) {// success
            NSString* fpVersion = @(response.fpVersion);
            NSString* blackBox = @(response.blackBox);
            NSString* anonymousId = @(response.anonymousId);
            NSString* message = @(response.apiStatus.message);
            NSString* sealedResult = @(response.sealedResult);
            int deviceRiskScore = response.deviceRiskScore;
        }
        else{// fail
            NSString* message = @(response.apiStatus.message);

        }
    });
let manager = TDDeviceManager.sharedManager()
    manager.pointee.getDeviceInfo() { (response: TDDeviceResponse!)->Void in
         let code = response.apiStatus.code
         // Char type strings must be converted to String type in multi-threaded situations, otherwise they will be released during thread switching
         if code == 0 {// success
             let fpVersion = String(validatingCString: response.fpVersion)
             let blackBox = String(validatingCString: response.blackBox)
             let anonymousId = String(validatingCString: response.anonymousId)
             let message = String(validatingCString: response.apiStatus.message)
             let sealedResult = String(validatingCString: response.sealedResult)
             let deviceRiskScore = response.deviceRiskScore
         }
         else {// fail
             let message = response.apiStatus.message
         }
     }

Status Check

  1. When the code of getDeviceInfo() callback == 0, it means that the device information is obtained successfully;

Response results

The getDeviceInfo() function returns the response data in callback , which contains the following information. sealedResult is returned only when client-side sealed results are enabled.

KeyDescription
anonymousIdDevice anonymous ID, device identification
blackBoxCall log query identifier
fpVersionSDK Version
deviceRiskScoreCurrent device risk score
sealedResultEncrypted device information, binary Base64 encoded string, returned only when the client seal result is turned on.

Other

Get SDK Version

TDDeviceManager_t *manager = [TDDeviceManager sharedManager];
NSString* sdkVersion = manager->getSDKVersion();
let manager = TDDeviceManager.sharedManager()
let sdkVersion = manager.pointee.getSDKVersion()

All Configurations

KeyDescriptionSampleRemove Field
partner(required)Partner code, contact operator to obtainObjective C
[options setValue:@"your partner" forKey:@"partner"];
Swift
options.updateValue("your partner" , forKey: "partner")
appKey(required)

Application identification, please refer to

how to get appKey

Objective C
[options setValue:@"your appKey" forKey:@"appKey"];
Swift
options.updateValue("your appKey" , forKey: "appKey")
country(required)Data-center: cn for China
fra for Europe
sg for Singapore idna for Indonesia us for USA
Objective C
[options setValue:@"cn" forKey:@"country"];
Swift
options.updateValue("cn" , forKey: "country")
channelChannel, contact operator to obtainObjective C
[options setValue:@"your channel" forKey:@"channel"];
Swift
options.updateValue("your channel", forKey: "channel")
timeLimitNetwork timeout configuration, in seconds, default 15sObjective C
[options setValue:@(5) forKey:@"timeLimit"];
Swift
options.updateValue(5, forKey: "timeLimit")
locationWhether collecting GPS location information, default allowedObjective C
[options setValue:@(YES) forKey:@"location"];
Swift
options.updateValue(true, forKey: "location")
latitude、longitude、gps_location
IDFAWhether collecting IDFA information, default allowedObjective C
[options setValue:@(YES) forKey:@"IDFA"];
Swift
options.updateValue(true, forKey: "IDFA")
idfa
IDFVWhether collecting IDFV information, default allowedObjective C
[options setValue:@(YES) forKey:@"IDFV"];
Swift
options.updateValue(true, forKey: "IDFV")
idfv
wifiIpWhether collecting wifiIp information, default allowedObjective C
[options setValue:@(NO) forKey:@"wifiIp"];
Swift
options.updateValue(false, forKey: "wifiIp")
wifiIp
cellIpWhether collecting cellIp information, default allowedObjective C
[options setValue:@(NO) forKey:@"cellIp"];
Swift
options.updateValue(false, forKey: "cellIp")
cellIp
vpnIpWhether collecting vpnIp information, default allowedObjective C
[options setValue:@(NO) forKey:@"vpnIp"];
Swift
options.updateValue(false, forKey: "vpnIp")
vpnIp
wifiIpv6Whether collecting wifiIpv6 information, default allowedObjective C
[options setValue:@(NO) forKey:@"wifiIpv6"];
Swift
options.updateValue(false, forKey: "wifiIpv6")
wifiIpv6
deviceNameWhether collecting device name information, default allowedObjective C
[options setValue:@(NO) forKey:@"deviceName"];
Swift
options.updateValue(false, forKey: "deviceName")
device_name
ssidWhether collecting ssid information, default allowedObjective C
[options setValue:@(NO) forKey:@"ssid"];
Swift
options.updateValue(false, forKey: "ssid")
ssid、bssid
customMessageCustom messages, SDK supports transparent transmission and storageObjective C
[options setValue:@"this is a customMessage" forKey:@"customMessage"];
Swift
options.updateValue("this is a customMessage", forKey: "customMessage")

Status Code

Call the TDDeviceManager getDeviceInfo() method. The parameter of type TDDeviceAPIStatus in the callback stores the status information of the SDK. Its definition is as follows:

typedef struct TDDeviceAPIStatus_Void {
    /// code
    int code;
    /// message
    NSString *message;
    
} TDDeviceAPIStatus;

The corresponding values of code and message are as follows:

CodeMessageRemarks
0Success.Success
1000Access error.Access exception occurs, possible causes: abnormal input parameters or network environment anomalies
1001SDK error.SDK exception occurs, possible reasons:Initialization function not called
1002Network error.Network Error
1003API error.The server returns an error
1004Traffic limit.Gateway current limiting return
1005Traffic shutdown.Traffic shutdown
1100Unknown error.Unknown error