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():
| Constant | Native Event | Description |
|---|---|---|
EVENT_SUCCESS | onScanningFinished | Emits MBNFCResult when reading completes |
EVENT_FAILURE | onFailureWithErrorMessage | Emits 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
- Always remove listeners on unmount to avoid memory leaks.
- Normalize MRZ inputs (e.g., uppercase document number).
- Validate dates are in
YYMMDDformat before callinglaunch. - Handle failure events via
EVENT_FAILUREto surface user-friendly errors.