Skip to main content

Quickstart

The React Native Document Reader SDK is provided as an NPM package that wraps the Mobai Document 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-document-reader

Or with yarn:

yarn add @mobaibio/mobai-document-reader

3. iOS Setup​

Add camera usage description to Info.plist:

<key>NSCameraUsageDescription</key>
<string>This app needs camera access to scan documents</string>

Then install pods:

cd ios && pod install && cd ..

4. Android Setup​

Ensure camera permission is present in AndroidManifest.xml:

<uses-permission android:name="android.permission.CAMERA" />

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 {
MobaiDocumentReaderModule,
EVENT_SUCCESS,
EVENT_FAILURE,
type MrzResult,
} from '@mobaibio/mobai-document-reader';
import { NativeEventEmitter } from 'react-native';

const eventEmitter = new NativeEventEmitter(MobaiDocumentReaderModule);

const successListener = eventEmitter.addListener(
EVENT_SUCCESS,
(event: MrzResult) => {
console.log('MRZ result', event);
}
);

const errorListener = eventEmitter.addListener(EVENT_FAILURE, (event) => {
console.log('Document reading error', event.onFailureWithErrorMessage);
});

MobaiDocumentReaderModule.launch(license);

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

For detailed implementation instructions, see the Implementation Guide.