ReactNative

Only supports Android and iOS

Requirements

Environment

AndroidiOS
Supported System VersionsAndroid 5.0 and aboveiOS 9.0 and above
Supported Architecturesarmeabi-v7a, arm64-v8a, x86armv7,arm64,x86_64

Integration

Installation

Adding Plugin

Execute the following command in the root directory of your React Native project:

   npm install --save react-native-trustdevice

Adding Dependencies

Android: In the build.gradle of the application module, declare SDK package dependencies.

dependencies {
    ...
    implementation 'com.trustdecision.android:apisign:1.1.3'
 }

iOS: Install(CocoaPods)

  • Add pod 'TrustDecisionAPISign', '1.1.1' to the corresponding target in the Podfile.
  • Execute the pod install --repo-update command in the folder containing the Podfile (For M1-series Mac computers, execute the command arch -x86_64 pod install --repo-update).

Best Practices

Invoke the plugin's sign method at the actual business node to sign the URL that requires signing.

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 *
 */

import React, { useState } from 'react';
import {
  StyleSheet,
  Text,
  View,
  Button,
} from 'react-native';

// import the plugin
import { NativeModules } from 'react-native';
const TrustDevice = NativeModules.TrustDevice;


function App(): JSX.Element {
  
  async function pathSign() {

    try {
      // the url that requires signing
	const path = "dev/v2"
	const signResult = await TrustDevice.sign(path);

	if (signResult.code == 0) {
	    // Signing successful. You can now proceed with the business logic using the sign result.
	    const sign = signResult.sign;
	    // todo
	} else {
    // signing failed

	    console.log('Signing failed:', signResult.msg)
  	}
    } catch (e) {
      // signing error
      console.log('Signing error:', e)
    }
     
  }


  return (
    <View style={styles.container}>
    </View>
  );
};

export default App;

Status Code

CodeDescriptionAction
0Success/
2000The path parameter is nullPlease set the path parameter
22xxInternal errorPlease contact technical support
30xxInternal errorPlease contact technical support
4001Failed to call the .so file, possibly because the SDK-dependent .so file is missingPlease check if the architecture used by the current device is configured in the project
4002Failed to call the SDK methodPlease verify if the apisign module has been integrated into the project

Additional Notes

Obfuscation Packaging

If Android requires using ProGuard for obfuscation packaging, please add the following code to the ProGuard configuration file:

-keep class com.trustdecision.**{*;}