Using the TMD SDK in a React Native project

We currently don’t provide a React Native module to use the TMD SDK from a React Native project. However, it is possible to make one by following the recommendations from the React Native documentation on how to make an iOS Native Module.

As a starting point, here is how you would start and stop the TMD from React Native:

  • First, in your iOS project (.xcworkspace file), add a new Objective-C class that looks like the following:
//  RCTTmdModule.h

#import <React/RCTBridgeModule.h>
@interface RCTTmdModule : NSObject <RCTBridgeModule>
@end
//  RCTTmdModule.m

#import "RCTTmdModule.h"
#import <MOPRIMTmdSdk/MOPRIMTmdSdk.h>

@implementation RCTTmdModule

// Export a module named RCTTmdModule:
RCT_EXPORT_MODULE();

RCT_EXPORT_METHOD(start)
{
  [TMD start];
}

RCT_EXPORT_METHOD(stop)
{
  [TMD stop];
}

@end
  • Then, in your React Native project, add the TMD module:
//  NativeTmdModule.js

import { NativeModules } from 'react-native';
const { TmdModule } = NativeModules;

interface TmdInterface {
  start(): void;
  stop(): void;
}

export default TmdModule;
  • You can now use your TMD module from your React Native app:
//  App.js

import TmdModule from './NativeTmdModule';

const onPressTmdStart = () => {
  TmdModule.start();
};
const onPressTmdStop = () => {
  TmdModule.stop();
};