npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-telematics

v1.0.10

Published

React Native wrapper for Telematics SDK

Downloads

46

Readme

Telematics SDK

A React Native wrapper for tracking the person's driving behavior such as speeding, turning, braking and several other things on iOS and Android.

Disclaimer: This project uses Telematics SDK which belongs to DATA MOTION PTE. LTD. When using Telematics SDK refer to these terms of use

Here you can find short video guides, how to add React Native Telematics SDK to your iOS and Android apps:

Watch the video

Watch the video

Example app


To run a TelematicsSdkExample application make sure that you have Node.js LTS version installed or install it from the official Node.js site. Also, make sure that you correctly configured the development environment according to React Native site instructions.

TelematicsSdkExample application is located in example directory

Inside the project folder install dependencies

yarn

To run an Android example

yarn example android

     -- or --

cd example
npx react-native run-android

To run an iOS example

yarn example ios

     -- or --

cd example
npx react-native run-ios

Installation


yarn add react-native-telematics

Getting started


Initial app setup & credentials


For commercial use, you need create a developer workspace in DataHub and get InstanceId and InstanceKey auth keys to work with our API.

Android


Add permissions in your project's AndroidManifest.xml:

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

Remove from your app AndroidManifest.xml line:

    android:allowBackup="true"

Add repository into (module)/gradle.build

dependencies {
    //...
    implementation "com.telematicssdk:tracking: x.x.x"
}

iOS


Add permissions in your project's ios/Runner/Info.plist:

<key>UIBackgroundModes</key>
<array>
    <string>fetch</string>
    <string>location</string>
    <string>remote-notification</string>
</array>
<key>NSMotionUsageDescription</key>
<string>Please, provide permissions for this Demo</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Please, provide permissions for this Demo</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>Please, provide permissions for this Demo</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>Please, provide permissions for this Demo</string>

And run in your project ios folder:

pod install

lifecycle handlers


Proper application lifecycle handling is extremely important for the TelematicsSdk. In order to use SDK you need to add lifecycle handlers to your application AppDelegate.mm:

// AppDelegate.mm

#import <RaxelPulse/RaxelPulse.h>

// ....

- (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);
    }];
}

Also add the SDK initialization before React Native bridge initialization


  [RPEntry initializeWithRequestingPermissions:NO];
  [RPEntry application:application didFinishLaunchingWithOptions:launchOptions];

  // before this line
  // RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];

React Native wrapper usage


import TelematicsSdk from "react-native-telematics";

// SDK initializing
TelematicsSdk.initialize()

// Requesting permissions
const isGranted = await TelematicsSdk.requestPermissions()
if(isGranted) {
  // All required permissions granted
} else {
  // Required permissions not granted
}

// Enabling and disabling SDK
const enabled = await TelematicsSdk.enable('Your device token goes here')
if(enabled) {
  // SDK is enabled successfully
} else {
  // SDK is not enabled
}
await TelematicsSdk.disable();

// SDK Status
const isEnabled = await TelematicsSdk.getStatus();
if(isEnabled) {
  // SDK is enabled
} else {
  // SDK is not enabled
}

// Future Tags API
// Add future tag
const result = await TelematicsSdk.addFutureTrackTag('Future tag name', 'Future tag source');
// Result object will contain SDK tag status and the tag you are adding
{
  status: string;
  tag: {
    tag: string;
    source?: string;
  }
}

// Get all future tags
const result = await TelematicsSdk.getFutureTrackTags();
// Result object will contain SDK tag status and all future tags
{
  status: string;
  tags: [
      tag: {
        tag: string;
        source?: string;
      }
  ]
}

// Remove all future tags
const result = await TelematicsSdk.removeAllFutureTrackTags();
// Result object will contain SDK tag status
{
  status: string;
}

// Remove single future tag
const result = await TelematicsSdk.removeFutureTrackTag('Future tag name');
// Result object will contain SDK tag status and the tag you are removing
{
  status: string;
  tag: {
    tag: string;
    source?: string;
  }
}

// iOS specific:
// Get an event for low power mode enabled
const eventEmitter = new NativeEventEmitter(TelematicsSdk);
const emitter = eventEmitter.addListener('onLowPowerModeEnabled', () => {
  console.log('Low power enabled');
});
// Don't forget to remove listener
emitter.remove();