API Reference
English

iOS

集成要求

环境要求

说明
兼容版本iOS9.0+
支持架构armv7, arm64, x86_64

安装(CocoaPods)

  • 在 Podfile 文件中对应 target 中新增 pod 'TrustDecisionPro', '5.1.1'
  • 在 Podfile 所在文件夹中执行 pod install --repo-update 命令 (arm架构mac电脑需要执行 arch -x86_64 pod install --repo-update 命令)

初始化

注意事项

  • 确保在用户同意隐私协议后,再进行SDK初始化。

引入头文件

在调用的位置引入头文件

#import <TDMobRisk/TDMobRisk.h>
import TDMobRisk

方法定义

void (*initWithOptions)(NSDictionary *options);

获取设备信息

注意事项

  • 请在 initWithOptions后调用getDeviceInfo

方法定义

void (*getDeviceInfo)(TDDeviceInfoCallback callback);

最佳实践

  1. 在应用程序入口处初始化
- (void)initDeviceManagerSDK {
  TDDeviceManager_t *manager = [TDDeviceManager sharedManager];
  NSMutableDictionary *options = [NSMutableDictionary dictionary];
  
  /*************************** 必传 ***************************/
  // 合作方编码,参考下方全部配置说明
  [options setValue:@"请输入您的合作方编码" forKey:@"partner"];
  // 平台注册的应用标识,参考下方全部配置说明
  [options setValue:@"请输入您的appKey" forKey:@"appKey"];
  // 数据中心地区参数,参考下方全部配置说明`
  [options setValue:@"请输入您所在的国家地区" forKey:@"country"];

  manager->initWithOptions(options);
}
func initDeviceManagerSDK() {
  let manager = TDDeviceManager.sharedManager()
  var options = Dictionary<String, Any>()
  /*************************** 必传 ***************************/
  // 合作方编码,参考下方全部配置说明
  options.updateValue("请输入您的合作方编码", forKey: "partner")
  // 平台注册的应用标识,参考下方全部配置说明
  options.updateValue("请输入您的appKey", forKey: "appKey")
  // 数据中心地区参数,参考下方全部配置说明
  options.updateValue("请输入您所在的国家地区", forKey: "country")

  manager.pointee.initWithOptions(options)
}
  1. 在实际业务节点获取设备信息
    TDDeviceManager_t *manager = [TDDeviceManager sharedManager];
    manager->getDeviceInfo(^(TDDeviceResponse response){
        int code = response.apiStatus.code;
        // char类型字符串在多线程情况下必须按以下方式转换成String类型,否则会在线程切换时被释放
        if(code == 0) {// 成功
            NSString* fpVersion = [[NSString alloc] initWithCString:response.fpVersion ?: "" encoding:NSUTF8StringEncoding];
            NSString* blackBox = [[NSString alloc] initWithCString:response.blackBox ?: "" encoding:NSUTF8StringEncoding];
            NSString* anonymousId = [[NSString alloc] initWithCString:response.anonymousId ?: "" encoding:NSUTF8StringEncoding];
            NSString* message = [[NSString alloc] initWithCString:response.apiStatus.message ?: "" encoding:NSUTF8StringEncoding];
            NSString* sealedResult = [[NSString alloc] initWithCString:response.sealedResult ?: "" encoding:NSUTF8StringEncoding];
            int deviceRiskScore = response.deviceRiskScore;
        }
        else{// 失败
            NSString* message = [[NSString alloc] initWithCString:response.apiStatus.message ?: "" encoding:NSUTF8StringEncoding];
        }
    });
    let manager = TDDeviceManager.sharedManager()
    manager.pointee.getDeviceInfo() { (response: TDDeviceResponse!)->Void in
         let code = response.apiStatus.code
         // char类型字符串在多线程情况下必须按以下方式转换成String类型,否则会在线程切换时被释放
         if code == 0 {// 成功
             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 {// 失败
             let message = response.apiStatus.message
         }
     }

状态检查

  1. 当getDeviceInfo() 回调的 code == 0 时即代表获取设备信息成功;

响应结果

getDeviceInfo() 函数会在 回调 中返回响应数据,包含以下信息。sealedResult 仅在启用了客户端密封结果时返回该信息。

字段描述
anonymousId设备匿名ID,设备标识
blackBox调用日志查询标识
fpVersionSDK版本号
deviceRiskScore当前设备风险分
sealedResult加密的设备信息,二进制 Base64 编码字符串,仅在客户端密封结果开启时返回,解密结果与设备信息查询获取的信息一致,参考:设备调用日志

其他说明

获取SDK版本号

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

全部配置

配置Key说明示例代码移除字段
partner(必须)合作方编码,请联系我司运营或者从客户平台获取Objective C
[options setValue:@"请输入您的合作方编码" forKey:@"partner"];
Swift
options.updateValue("请输入您的合作方编码" , forKey: "partner")
appKey(必须)应用标识,通过客户平台创建,参考如何申请appKeyObjective C
[options setValue:@"请输入您的appKey" forKey:@"appKey"];
Swift
options.updateValue("请输入您的appKey" , forKey: "appKey")
country(必须)数据中心地区:
cn代表中国
us代表美国
sg代表新加坡
fra代表德国
idna代表印尼
Objective C
[options setValue:@"cn" forKey:@"country"];
Swift
options.updateValue("cn" , forKey: "country")
channel渠道标识,请联系运营获取Objective C
[options setValue:@"请输入您的channel" forKey:@"channel"];
Swift
options.updateValue("请输入您的channel", forKey: "channel")
timeLimit网络请求回调的超时时间,单位秒,默认为15sObjective C
[options setValue:@(5) forKey:@"timeLimit"];
Swift
options.updateValue(5, forKey: "timeLimit")
location是否采集地理位置信息,默认开启Objective C
[options setValue:@(NO) forKey:@"location"];
Swift
options.updateValue(false, forKey: "location")
latitude、longitude、gps_location
IDFA是否采集广告标识符,默认开启Objective C
[options setValue:@(NO) forKey:@"IDFA"];
Swift
options.updateValue(false, forKey: "IDFA")
idfa
IDFV是否采集应用开发厂商标识符,默认开启Objective C
[options setValue:@(NO) forKey:@"IDFV"];
Swift
options.updateValue(false, forKey: "IDFV")
idfv
wifiIp是否采集 wifiIp,默认开启Objective C
[options setValue:@(NO) forKey:@"wifiIp"];
Swift
options.updateValue(false, forKey: "wifiIp")
wifiIp
cellIp是否采集 cellIp,默认开启Objective C
[options setValue:@(NO) forKey:@"cellIp"];
Swift
options.updateValue(false, forKey: "cellIp")
cellIp
vpnIp是否采集 vpnIp,默认开启Objective C
[options setValue:@(NO) forKey:@"vpnIp"];
Swift
options.updateValue(false, forKey: "vpnIp")
vpnIp
wifiIpv6是否采集 wifiIpv6,默认开启Objective C
[options setValue:@(NO) forKey:@"wifiIpv6"];
Swift
options.updateValue(false, forKey: "wifiIpv6")
wifiIpv6
deviceName是否采集设备名称,默认开启Objective C
[options setValue:@(NO) forKey:@"deviceName"];
Swift
options.updateValue(false, forKey: "deviceName")
device_name
ssid是否采集ssid信息,默认开启Objective C
[options setValue:@(NO) forKey:@"ssid"];
Swift
options.updateValue(false, forKey: "ssid")
ssid
collectLevel配置降级 blackBox 裁剪长度,默认情况为5000字符左右,配置M后大部分在2000-5000字符区间,目前仅支持这两种配置。Objective C
[options setValue:@"M" forKey:@"collectLevel"];
Swift
options.updateValue("M", forKey:"collectLevel")
customMessage自定义消息,sdk支持透传和存储Objective C
[options setValue:@"this is a customMessage" forKey:@"customMessage"];
Swift
options.updateValue("this is a customMessage", forKey: "customMessage")

状态码说明

调用TDDeviceManager getDeviceInfo()方法,回调中TDDeviceAPIStatus类型的参数保存着SDK的状态信息,它的定义如下:

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

code和message对应值如下表:

codemessage备注
0Success.成功
1000Invalid parameters.传入的参数无效
1001SDK error.SDK 发生异常,可能原因: 未调用初始化函数
1002Network error.网络错误
1003API error.后端接口返回错误
1004Traffic limit.网关限流返回