Skip to content

Installation

Minimum Requirements:

  • Cordova: 6.0.0+
  • cordova-android: 6.2.3+ & 7.X.X
  • cordova-ios: 4.4.0+

Prerequisites

The cordova-plugin-nearit automates many configuration steps for you. To be sure these steps will work, please install these Node dependencies:

npm install shelljs elementtree plist xml2js --save-prod

Install the plugin

To start using the SDK, add this plugin to your Cordova project

cordova plugin add cordova-plugin-nearit
ionic cordova plugin add cordova-plugin-nearit
phonegap plugin add cordova-plugin-nearit


NearIT API Key

You can find your API key on NearIT web interface, navigate to "Settings > SDK Integration" section.

Add a preference to your config.xml file

<preference name="near_api_key" value="YOUR_API_KEY" />


Test devices

Go to NearIT web interface, navigate to "Settings > Test devices" section.

The Android setup will present you a snippet like this:

urlscheme

copy the string highlighted in the screenshot and paste it in your config.xml as a preference, like this:

<preference name="near_url_scheme" value="YOUR_URL_SCHEME" />


Auto update (iOS)

The SDK will automatically check for new content. You can set the minimun background fetch interval in your config.xml file, 2 hours (7200 seconds) is the recommended value:

<preference name="minimum_background_fetch_interval" value="7200" />


Finalize installation

When you have installed and configured the plugin, run the prepare command:

cordova prepare
ionic cordova prepare
phonegap prepare


Initialization

A new nearit object will be added to the global scope (as window.nearit), this is the entry point for each method described later.

In your javascript notify the plugin that your app is up and running: depending on the framework you are using add the following snippet inside "ready" or "deviceReady" callbacks:

if (window.nearit) {
  nearit.onDeviceReady();
}
const nearit = (window as any).nearit;
if (nearit) {
  nearit.onDeviceReady();
}