Skip to main content

NFC Module Integration Guide

The React Native NFC Reader module exposes the native Mobai NFC SDKs through a Native Module and event emitter.


Native Module API

Module and Launch Function

import { MobaiNfcReader, launch } from '@mobaibio/mobai-nfc-reader';

launch signature:

launch(license: string, documentNumber: string, dateOfExpiry: string, dateOfBirth: string)

Events

The module provides two event constants from getConstants():

ConstantNative EventDescription
EVENT_SUCCESSonScanningFinishedEmits MBNFCResult when reading completes
EVENT_FAILUREonFailureWithErrorMessageEmits MBCaptureSessionError on failure

Data Models

MBNFCResult

export interface MBNFCResult {
firstName: string;
lastName: string;
gender: string;
birthDate: string;
nationality: string;
dateOfExpiry: string;
issuingStateOrOrganization: string;
documentNumber: string;
issueDate: string;
placeOfBirth: string;
portrait: string;
dataGroups: { [dgName: string]: string };
}

MBCaptureSessionError

export interface MBCaptureSessionError {
errorDescription: string;
}

Full React Native Flow Example

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

export function NfcReaderScreen({ mrzData, license }: any) {
useEffect(() => {
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);
}
);

return () => {
successListener.remove();
errorListener.remove();
};
}, []);

const startReading = () => {
launch(
license,
mrzData.documentNumber.toUpperCase(),
mrzData.dateOfExpiry,
mrzData.dateOfBirth
);
};

return null;
}

Best Practices

  1. Always remove listeners on unmount to avoid memory leaks.
  2. Normalize MRZ inputs (e.g., uppercase document number).
  3. Validate dates are in YYMMDD format before calling launch.
  4. Handle failure events via EVENT_FAILURE to surface user-friendly errors.