Skip to main content

Quickstart

The React Native NFC Reader SDK is provided as an NPM package that wraps the Mobai NFC Reader SDKs for iOS and Android.

Installation

1. Configure the NPM Registry

The React Native packages are hosted in Mobai's GitLab NPM registry. Add the following to your project-level .npmrc:

@mobaibio:registry=https://gitlab.com/api/v4/projects/36441060/packages/npm/
//gitlab.com/api/v4/projects/36441060/packages/npm/:_authToken=YOUR_PERSONAL_ACCESS_TOKEN

2. Install the Package

npm i @mobaibio/mobai-nfc-reader

Or with yarn:

yarn add @mobaibio/mobai-nfc-reader

3. iOS Setup

  1. Info.plist

Add the NFC usage description:

<key>NFCReaderUsageDescription</key>
<string>This app needs NFC access to read travel documents</string>
  1. Entitlements

Ensure NFC reader session formats are enabled:

<key>com.apple.developer.nfc.readersession.formats</key>
<array>
<string>NDEF</string>
<string>TAG</string>
</array>
  1. Install Pods
cd ios && pod install && cd ..

4. Android Setup

Add NFC permissions to AndroidManifest.xml:

<uses-permission android:name="android.permission.NFC" />
<uses-feature android:name="android.hardware.nfc" android:required="true" />

License Setup

The SDK expects a license string (JSON). Create a helper that loads your license JSON:

const licenseSrc = {}; // replace with the JSON object from your license file
export const license: string = JSON.stringify(licenseSrc);

Basic Usage

import {
EVENT_SUCCESS,
EVENT_FAILURE,
launch,
MobaiNfcReader,
type MBNFCResult,
type MBCaptureSessionError,
} from '@mobaibio/mobai-nfc-reader';
import { NativeEventEmitter } from 'react-native';

const eventEmitter = new NativeEventEmitter(MobaiNfcReader);

const successListener = eventEmitter.addListener(
EVENT_SUCCESS,
(result: MBNFCResult) => {
console.log('NFC result', result);
}
);

const errorListener = eventEmitter.addListener(
EVENT_FAILURE,
(error: MBCaptureSessionError) => {
console.log('NFC error', error.errorDescription);
}
);

launch(
license,
documentNumber.toUpperCase(),
dateOfExpiry,
dateOfBirth
);

// Cleanup
successListener.remove();
errorListener.remove();

For detailed implementation instructions, see the Implementation Guide.