SDK for React Native app

1. SDK Installation

Please make sure you use the latest version of Telematics SDK recent version. Link to the RaxelPulse iOS framework with CocoaPods rather than downloading the framework itself.

  • Navigate to your project folder in a terminal window.
  • Make sure you have the CocoaPods gem installed on your machine before installing the Raxel Pulse pod

1.1. Create a file "Podfile" in your project's root directory.

$ sudo gem install cocoapods$ pod init

1.2. Add Telematics SDK to your Podfile:

pod 'RaxelPulse'

1.3. Complete the installation

$ pod install

2. Create iOS Bridge

2.1. For Native side

Create the native files for your module by opening your workspace file on Xcode, select your project, and right-click to add a new file. Select Cocoa Touch Class, give the name, and create it.

Step 1 - BridgeClassDemo.h
Create the bridge by copying the code below into your BridgeClassDemo.h file

//
//  BridgeClassDemo.h
//  TelematicsSDKReactNativeDemo
//
//  Created by Sergey Emelyanov on 19/04/2020.
//  Copyright © 2020 Data motion Pte.Ltd. All rights reserved.
//  https://telematicssdk.com
​
#import "React/RCTBridgeModule.h"
​
// Instead of BridgeClassDemo put the name of your module
@interface BridgeClassDemo : NSObject <RCTBridgeModule>
@end

Step 2 - DemoClass.m
Add the code below into your DemoClass.m file:

//
//  DemoClass.m
//  TelematicsSDKReactNativeDemo
//
//  Created by Sergey Emelyanov on 19/04/2020.
//  Copyright © 2020 Data motion Pte.Ltd. All rights reserved.
//  https://telematicssdk.com

#import <React/RCTLog.h>
#import <RaxelPulse/RaxelPulse.h>
#import <AdSupport/AdSupport.h>
#import "BridgeClassDemo.h" // Here put the name of your module

@implementation BridgeClassDemo // Here put the name of your module

// This RCT (React) "macro" exposes the current module to JavaScript

RCT_EXPORT_MODULE(BridgeClassDemo);

RCT_EXPORT_METHOD(start:(NSString *)token) {
  dispatch_async(dispatch_get_main_queue(), ^{
    [RPEntry instance].virtualDeviceToken = @"DeviceToken";
    [RPEntry instance].disableTracking = NO;
  });
}

RCT_EXPORT_METHOD(enableSDK) {
  dispatch_async(dispatch_get_main_queue(), ^{
      [[RPEntry instance] setEnableSdk: true];
  });
}

RCT_EXPORT_METHOD(disableSDK) {
  dispatch_async(dispatch_get_main_queue(), ^{
      [[RPEntry instance] setDisableWithUpload];
  });
}

/** You can add any required methods by yourself 
* using this code as a template

RCT_EXPORT_METHOD(yourmetod) {
  dispatch_async(dispatch_get_main_queue(), ^{
      //Your native command
  });
}

*/

@end

Step 3 - AppDelegate
Handle library methods for AppDelegate as it is in the example below:

#import "AppDelegate.h"
#import <React/RCTBridge.h>
#import <React/RCTRootView.h>
#import <RaxelPulse/RaxelPulse.h>
#import <React/RCTLog.h>
#import <AdSupport/AdSupport.h>

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  [[RPCPermissionsWizard returnInstance] launchWithFinish:^(BOOL showWizzard) {
    [RPEntry initializeWithRequestingPermissions:YES];
  }];
  RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
  RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
    moduleName:@"RCdemo_mobile"
    initialProperties:nil];
  self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  UIViewController *rootViewController = [UIViewController new];
  rootViewController.view = rootView;
  self.window.rootViewController = rootViewController;
  [self.window makeKeyAndVisible];
  return YES;
}
  
- (void)application:(UIApplication *)application handleEventsForBackgroundURLSession:(nonnull NSString *)identifier completionHandler:(nonnull void (^)(void))completionHandler {
  [RPEntry application:application handleEventsForBackgroundURLSession:identifier completionHandler:completionHandler];
}
  
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
  [RPEntry applicationDidReceiveMemoryWarning:application];
}
  
- (void)applicationWillTerminate:(UIApplication *)application {
  [RPEntry applicationWillTerminate:application];
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
  [RPEntry applicationDidEnterBackground:application];
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
  [RPEntry applicationDidBecomeActive:application];
}

- (void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
  [RPEntry application:application performFetchWithCompletionHandler:^{
    completionHandler(UIBackgroundFetchResultNewData);
  }];
}

@end

2.2. For ReactNative side

Now, you call the functions anywhere on the ReactNative side:

import { NativeModules } from 'react-native';
var BridgeClassDemo = NativeModules.BridgeClassDemo;
//Let's show it
BridgeClassDemo.start(@"DeviceToken")
BridgeClassDemo.enableSDK()
BridgeClassDemo.disableSDK()
//BridgeClassDemo.yourmetod()

2.3. Summary

To add a new method, you have to add to DemoClass.m (Native part)

RCT_EXPORT_METHOD(yourmetod) {
  dispatch_async(dispatch_get_main_queue(), ^{
      //Your native command
  });

And to anywhere in ReactNative

BridgeClassDemo.yourmetod()

Did this page help you?