Installing the SDK

This guide will help you setup the React Native module in your application. The module is built on top of native iOS and Android SDKs, which collect location, activity and device health. The module exposes methods to start and stop tracking, and interact with the HyperTrack APIs.

In case you are not using React Native, you can refer to the iOS or Android versions. If you're looking for an example integration, use the example react native application.

Step 1: Install the module

In your project directory, install from npm, and then link it.

$ npm install react-native-hypertrack --save
$ react-native link react-native-hypertrack

Step 2: Setup native dependencies

iOS

  1. The native iOS SDKs need to be setup using Cocoapods. In your project's ios directory, create a Podfile.

  2. Edit the Podfile to include HyperTrack as a dependency for your project, and then install the pod.

  3. Now, open the iOS project with the .xcworkspace file in Xcode, and add the HyperTrack.framework file to the linked frameworks and libraries section if they are not already added by Cocoapods.

$ cd ios
$ pod init
# ios/Podfile
target 'AppName' do
  use_frameworks!

  # Pods for AppName
  pod 'HyperTrack'

  post_install do |installer|
    installer.pods_project.targets.each do |target|
      target.build_configurations.each do |config|
        config.build_settings['SWIFT_VERSION'] = '3.0'
      end
    end
  end
end

Manual linking on iOS

After the Cocoapods are setup, we need to manually link the wrapper code. This is a required step, in addition to the link command described previously.

  1. Open the iOS module files, located inside node_modules/react-native-hypertrack/_ios/.
  2. Open the app workspace file (AppName.xcworkspace) in Xcode.
  3. Move the RNHyperTrack.h and ios/RNHyperTrack.m files to your project. When shown a popup window, select Create groups.

Linking on iOS

Android

To use the HyperTrack Android SDKs, the repository url need to be added to your android/build.gradle file. Once you run Gradle sync, the native SDK will be setup in the app. Refer to Android troubleshoot, in case you run into Gradle errors.

allprojects {
    repositories {
        ...
        maven { url 'http://hypertrack-android-sdk.s3-website-us-west-2.amazonaws.com/' }
    }
}

Build tools

In your android/app/build.gradle file, update the build SDK versions.

compileSdkVersion 25
buildToolsVersion "25.0.1"

Step 3: Importing the module

iOS

import { NativeModules } from 'react-native';
var RNHyperTrack = NativeModules.RNHyperTrack;

Android

import RNHyperTrack from 'react-native-hypertrack';

Combined

If you have a common app file for both Android and iOS, you can use the following snippet to define RNHyperTrack.

import { NativeModules } from 'react-native';
import {RNHyperTrack as RNHyperTrackImport} from 'react-native-hypertrack';

if (NativeModules.RNHyperTrack != undefined) {
  // Import for iOS setup
  var RNHyperTrack = NativeModules.RNHyperTrack;
} else {
  // Import for Android setup
  var RNHyperTrack = RNHyperTrackImport;
}

Step 4: Configure the API key

To configure the SDK, set the publishable key. This can be done in the constructor of your component class.

export default class MyApp extends Component {
  constructor() {
    super();
    // Initialize HyperTrack wrapper
    RNHyperTrack.initialize('YOUR_PUBLISHABLE_KEY');
  }
}

Step 5: Native capabilities

Follow these steps to setup native capabilities for iOS and Android.

Step 6: Request for permissions

Android

The SDK requires Location Permission to be granted and Location Services to be enabled in High Accuracy.

// Call this method to request Location Authorization for Android & iOS (Always Authorization).
// NOTE: In Android, the Permission dialog box's title and message can be customized by passing them as parameters.
RNHyperTrack.requestLocationAuthorization(title, message);

iOS

The SDK requires Location & Motion permissions to be granted. Make sure that the permission strings (see previous step) are defined in your app.

// Call this method to request Location Authorization for Android & iOS (Always Authorization).
// NOTE: In iOS, the permission strings are used to define message. Parameters title and message are ignored.
RNHyperTrack.requestLocationAuthorization(title, message);

// Call this method to request Motion Authorization for iOS.
// NOTE: Motion Authorization is required only for iOS. This API will return an error in Android.
RNHyperTrack.requestMotionAuthorization();

Authorization status

The SDK also has helper methods to check authorization statuses.

// Call this method to check location authorization status.
RNHyperTrack.locationAuthorizationStatus().then((status) => {
  // Handle locationAuthorizationStatus API promise here
  console.log('locationAuthorizationStatus: ', status);
});

// Call this method to check location services are enabled or not.
RNHyperTrack.locationServicesEnabled().then(
  (callback) => {
    // Handle locationServicesEnabled API callback here
    console.log('locationServicesEnabled: ', callback);
  }
);

// Call this method to check if Motion Activity API is available on the device
// NOTE: Motion Authorization is required only for iOS. This API will return an error in Android.
RNHyperTrack.canAskMotionPermissions().then(
  (callback) => {
    // Handle canAskMotionPermissions API callback here
    console.log('canAskMotionPermissions: ', callback);
  }
);

results matching ""

    No results matching ""