仅支持Android和iOS
集成要求
环境要求
| Android | iOS | |
|---|---|---|
| 兼容版本 | Android 5.0及以上系统 | iOS9.0及以上系统 |
| 支持架构 | armeabi, armeabi-v7a, arm64-v8a, x86 | armv7,arm64,x86_64 |
集成步骤
插件安装
在您的 ReactNative 项目根目录中执行
npm install --save react-native-trustdevice添加依赖
Android: 在应用主模块的 build.gradle 中,声明SDK包依赖
dependencies {
...
implementation 'com.trustdecision.android:apisign:+'
}iOS: 安装(CocoaPods)
- 在 Podfile 文件中对应 target 中新增 pod 'TrustDecisionAPISign'
- 在 Podfile 所在文件夹中执行 pod install --repo-update 命令 (M1系列mac电脑需要执行 arch -x86_64 pod install --repo-update 命令)
集成示例
在实际业务节点调用插件 sign 方法对需要加签的 url 进行签名
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
*/
import React, { useState } from 'react';
import {
StyleSheet,
Text,
View,
Button,
} from 'react-native';
// 引入插件
import { NativeModules } from 'react-native';
const TrustDevice = NativeModules.TrustDevice;
function App(): JSX.Element {
// 加签
async function pathSign() {
try {
const signResult = await TrustDevice.sign('dev/v2');
if (signResult.code == 0) {
// 加签成功,可使用签名结果sign继续业务逻辑
const sign = signResult.sign;
// todo
} else {
// 加签失败
console.log('sign fail:', signResult.msg)
}
} catch (e) {
// 加签异常
console.log('sign error:', e)
}
}
return (
<View style={styles.container}>
</View>
);
};
export default App;状态码
| 状态码 | 信息描述 | 处理方式 |
|---|---|---|
| 0 | 成功 | / |
| 2000 | path为空 | 请设置path参数 |
| 22xx | 内部错误 | 请联系技术支持 |
| 30xx | 内部错误 | 请联系技术支持 |
| 4001 | 调用so文件失败,可能是SDK依赖的so文件已经缺失 | 请检查当前设备所使用的架构是否有配置到项目中 |
| 4002 | 调用SDK失败 | 请检查apisign模块是否引入到项目中 |
其他说明
混淆打包
如果 Android 需要使用 proguard 进行混淆打包,请在 proguard 配置文件添加如下代码:
-keep class com.trustdecision.**{*;}