Skip to content

TrueTime library for React native to get accurate time from ntp servers

Notifications You must be signed in to change notification settings

soarb/react-native-truetime

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-native-truetime

Getting started

$ npm install react-native-truetime --save

Mostly automatic installation

$ react-native link react-native-truetime

Additional Steps (iOS and CocoaPods)

add 'TrueTime' to your Podfile and run pod install

Note that this is a Swift library and most react-native projects are all in Objective-C, so if you encounter link errors building the project, I've found that adding an empty Swift file to your project will prompt XCode to include an Objective-C bridge, which for me at least, fixed the linker errors. This at least means you don't need to uncomment use_frameworks! in your Podfile which fixes the issue but can break other modules e.g., React Native Firebase.

Manual installation

Android

  1. Open up android/app/src/main/java/[...]/MainActivity.java
  • Add import com.pkgarg.truetime.RNTrueTimePackage; to the imports at the top of the file
  • Add new RNTrueTimePackage() to the list returned by the getPackages() method
  1. Append the following lines to android/settings.gradle:
    include ':react-native-truetime'
    project(':react-native-truetime').projectDir = new File(rootProject.projectDir, 	'../node_modules/react-native-truetime/android')
    
  2. Add maven repository to android/build.gradle:
    allprojects {
        repositories {
            maven { url "https://jitpack.io" }  // Add this line
        }
    }
    
  3. Insert the following lines inside the dependencies block in android/app/build.gradle:
      compile project(':react-native-truetime')
      compile 'com.github.instacart.truetime-android:library-extension-rx:3.3'
    

Usage

import RNTrueTime from 'react-native-truetime';

// Initialize TrueTime
RNTrueTime.initTrueTime()

// Returns time in millisecond (as a string)
...
const trueTimeStr = await RNTrueTime.getTrueTime();
const trueTime = parseInt(trueTimeStr);

About

TrueTime library for React native to get accurate time from ntp servers

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 65.4%
  • Objective-C 25.9%
  • Ruby 7.3%
  • JavaScript 1.4%