Collecting the Responses
Warning
The startOcr Promise resolves with a JSON string, on both Android and iOS. You must call JSON.parse() before accessing the fields. The declared TypeScript type is OCR_RETURN_VALUES | string.
Response structure
type OCR_RETURN_VALUES = {
DocumentRecognitionResponse: {
ocr_key?: string;
ocr_front_key?: string;
ocr_back_key?: string;
document_type: string;
}[];
};
| Attribute | Type | Description |
|---|---|---|
| ocr_key | string | Image identification key, present for single-capture documents (cnh_full, cnh_digital, proof_of_address, rg_cin_digital). It can be used in any other service of the QI Tech system. |
| ocr_front_key | string | Identification key of the front image, present for dual-capture documents (cnh, rg, rne, crnm). |
| ocr_back_key | string | Identification key of the back image, present for dual-capture documents (cnh, rg, rne, crnm). |
| document_type | string | Identifies which document that key refers to (e.g. "cnh", "rg", "proof_of_address"). |
Important
Store the returned keys — they are the image identifier in the other products of the QI Tech system, such as the Onboarding API.
Single-capture document
{
"DocumentRecognitionResponse": [
{ "ocr_key": "5d0f0e1c-8f9e-4b6c-9c3d-2f8a1b4e7c10", "document_type": "cnh_full" }
]
}
Dual-capture document
{
"DocumentRecognitionResponse": [
{ "ocr_front_key": "5d0f0e1c-8f9e-4b6c-9c3d-2f8a1b4e7c10", "document_type": "cnh" },
{ "ocr_back_key": "a1b2c3d4-5e6f-4a7b-8c9d-0e1f2a3b4c5d", "document_type": "cnh" }
]
}
Reading the response
startOcr(CAAS_ENVIRONMENT.SANDBOX, mobileToken, CAAS_DOCUMENT_TYPE.CNH)
.then((response) => {
const { DocumentRecognitionResponse } = JSON.parse(response as string);
if (DocumentRecognitionResponse.length === 1) {
const { ocr_key, document_type } = DocumentRecognitionResponse[0];
console.log('Ocr key: ' + ocr_key + ' document type: ' + document_type);
} else if (DocumentRecognitionResponse.length === 2) {
const { ocr_front_key } = DocumentRecognitionResponse[0];
const { ocr_back_key } = DocumentRecognitionResponse[1];
console.log('Ocr front key: ' + ocr_front_key + ' / Ocr back key: ' + ocr_back_key);
}
})
.catch((error) => {
console.log('Error executing Ocr. Error: ' + error);
});
Error handling
The Promise is rejected when the user interrupts the flow or when the native SDK encounters an error.
| Situation | Message |
|---|---|
| User canceled the flow | User canceled OCR |
| Error in the native iOS SDK | Error executing OCR: <detail> |
| Native module not linked | The package 'react-native-qi-tech-module' doesn't seem to be linked... |
Warning
If you get the linking error, check that you ran pod install on iOS, that you rebuilt the app after installing the package, and that you are not in the Expo managed workflow without prebuild.