Document Capture

In this section, you will find all the necessary information for using and integrating the Unico IDCloud SDK into your iOS applications for document capture


This guide has been designed to help you quickly and easily implement the Android SDK. Below, you'll find the step-by-step process for the complete integration. If you wish to customize the experience further, check out the iOS Customization section.

Available Document Frames


In this camera mode, there is a capture frame to assist the user in positioning the document correctly. After positioning the document correctly, the user should click the button to capture the photo of the document.

In this camera mode, it is possible to capture the following documents:

  • RG: Capture of the RG (separate front and back).

  • CNH: Capture of the CNH opened.

  • CNH Front: Capture of the front of the CNH.

  • CNH Back: Capture of the back of the CNH.

  • CPF: Capture of the CPF document.

  • Without Silhouette: Capture of a generic document.

Initializing the SDK


To get started with the Unico IDCloud iOS SDK, import the SDK and implement the AcessoBioManagerDelegate interface within the ViewController you wish to use.

The implementation of this class is straightforward and can be done with just a few lines of code. All you need to do is instantiate the builder by providing the relevant context and override the callback methods with the business logic of your application:

.m:
#import "ViewController.h"
#import <AcessoBio/AcessoBio.h>

@interface ViewController ()
@end

@implementation ViewController
- (void)viewDidLoad {
    [super viewDidLoad];   
    unicoCheck = [[AcessoBioManager alloc]initWithViewController:self];
}
   
- (void)onErrorAcessoBioManager:(ErrorBio *)error {
  // Your code
}

- (void)onSystemChangedTypeCameraTimeoutFaceInference {
  // Your code
}

- (void)onSystemClosedCameraTimeoutSession {
  // Your code
}

- (void)onUserClosedCameraManually {
  // Your code
}

@end

Implementing Callback Functions


Note that, as shown in the previous example, the implementation work of the AcessoBioManagerDelegate interface is largely about configuring the callback methods. Each method is called in a specific situation based on the SDK's response.

Simply override the methods illustrated in the previous step with your application's business logic:

1

onErrorAcessoBioManager(_ error: ErrorBio!)

This method is invoked whenever an implementation error occurs while using any of the methods, such as providing an incorrect document type for the document capture functionality.

When invoked, the method receives a parameter of type ErrorBio, which contains details about the error. Learn more about the ErrorBio type in the error handling article of this SDK.

2

onUserClosedCameraManually()

This method is invoked whenever the user manually closes the camera, such as by clicking the "Back" button.

3

onSystemClosedCameraTimeoutSession()

This method is also invoked once the maximum session time is reached (without capturing any image).

4

onSystemChangedTypeCameraTimeoutFaceInference()

This method is invoked once the maximum time for detecting the user's face is reached (without detecting anything). In this case, the camera mode is automatically switched to manual capture mode (without the intelligent capture silhouette).

Implementing Delegates for Camera Events


The camera opening method (which is called in the next step) needs to know what to do when it successfully captures an image or encounters an error during the process. The "actions" to be taken are specified to the camera opening method through the configuration of delegates, which are called in success or error situations.

By configuring the delegates, you can define what happens in your app during error situations (onErrorDocument method) or success situations (onSuccessDocument method) when capturing images.

To configure the delegates, you need to implement the DocumentCameraDelegate and AcessoBioDocumentDelegate interfaces:

.h:
#import <UIKit/UIKit.h>
#import <AcessoBio/AcessoBio.h>
#import "SelfieCameraDelegate.h"

@interface ViewController: UIViewController <AcessoBioManagerDelegate, DocumentCameraDelegate, 
  AcessoBioDocumentDelegate> {
  AcessoBioManager *unicoCheck;
  // Your code from previous and next steps here
}

onSucessDocument Method


When an image is successfully captured, this method is invoked and returns an object of type ResultCamera, which is used later in the REST API request.

- (void)onSuccessDocument:(DocumentResult *)result {
    NSLog(@"%@", result.base64);
} 

The ResultCamera object returns two attributes: base64 and encrypted.

  • The base64 attribute can be used if you want to display a preview of the image in your app.

  • Both the encrypted and base64 attributes can be sent in the REST API calls of the by Client.

Método onErrorDocument


When an error occurs during image capture, this method is invoked and returns an object of type ErrorBio.

- (void)onErrorDocument:(ErrorBio *)errorBio {
    // Your code
}

Learn more about the ErrorBio types in the error handling section of the SDK.

Preparing and Opening the Camera


To open the camera, it is necessary to prepare it using the method prepareDocumentCamera. This method takes as a parameter the implementation of the DocumentCameraDelegate class and the JSON with the credentials generated in the previous step.

.h:
#import <UIKit/UIKit.h>
#import <AcessoBio/AcessoBio.h>
#import "SelfieCameraDelegate.h"

@interface ViewController: UIViewController < AcessoBioManagerDelegate,
DocumentCameraDelegate, AcessoBioDocumentDelegate> {
    AcessoBioManager *unicoCheck;
}

.m:
- (IBAction)openCamera:(UIButton *)sender {
    [[unicoCheck build] prepareDocumentCamera:self config:[YourUnicoConfigClass new]];
}

When the camera is ready, the event onCameraReadyDocument is triggered, which receives as a parameter an object of type AcessoBioCameraOpenerDelegate.

You should override this method, opening the camera with the object received through the openDocument() method, receiving the document type parameters to be captured, which are:

Parameter
Description

DocumentEnums.CPF

Capture the front of the CPF

DocumentEnums.CNH

Capture the open CNH

DocumentEnums.cnhFrente

Capture the front of the CNH

DocumentEnums.cnhVerso

Capture the back of the CNH

DocumentEnums.RG

Capture the open RG

DocumentEnums.rgFrente

Capture the front of the RG

DocumentEnums.rgVerso

Capture the back of the RGo RG

DocumentEnums.none

Capture any other document

The delegates implemented above (referred to here as Self):

- (void)onCameraReadyDocument:(id)cameraOpener {
    [cameraOpener openDocument:DocumentCNH delegate:self];
}

- (void)onCameraFailedDocument:(ErrorPrepare *)message {
  // Your code
}

The ErrorPrepare type is an extension of ErrorBio, thus containing all its properties. Learn more about the ErrorBio type in the SDK error handling section.

If an error occurs while preparing the camera, the onCameraFailedDocument event is triggered. You should implement this method according to the business logic of your app.

In case of success, the onSuccessDocument event is triggered, as explained in the section above.

Making a POST Request to the Client API


Capturing the images is only the first part of the journey. After capturing the image, you need to send the base64 generated by the SDK to the by Client REST APIs. Learn more in the CreateProcess section of the by Client.


Still need help?

Didn't find something or still need help? If you're already a client or partner, you can reach out through our Help Center.

Last updated

Was this helpful?