Selfie Capture

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


This guide has been created to help you implement the Unico iOS SDK quickly and easily. Below is the step-by-step process for the entire integration. Afterward, if you wish to personalize the experience, be sure to check the iOS Customization section.

Initializing the SDK


To get started with the Unico Check iOS SDK, import the SDK and implement the AcessoBioManagerDelegate interface within the ViewController you want 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, providing the context and environment in question, and override the callback methods with the business logic of your application:

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

@implementation ViewController: UIViewController
- (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

Environment configuration


Configure the environment that will be used to run the SDK. Use the enumerated environment that contains the following enumerates:

  • PROD: for production environment;

  • UAT: for approval environment.

See how to implement it in the example below:

  [unicoCheck setEnvironment:UAT];

Implementing the Callback Functions


Note that, as shown in the previous example, the implementation of the AcessoBioManagerDelegate interface mainly involves configuring the callback methods. Each method is called in a specific situation in the SDK's return process.

You simply need to override the methods demonstrated in the previous step with the business logic of your application:

1

onErrorAcessoBioManager(_ error: ErrorBio!)

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

When invoked, the method will receive a parameter of type ErrorBio that contains details of the error. For more information on the ErrorBio type, refer to the error handling article in this SDK documentation.

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 invoked as soon as the maximum session time is reached (without capturing any image).

4

onSystemChangedTypeCameraTimeoutFaceInference()

This method is invoked as soon as the maximum time for detecting a 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).

Configuring Camera Mode


The SDK has intelligent framing and automatic capture configured and enabled by default. As a result, you should configure the camera mode in your builder as follows:

.m:
- (IBAction)configureSmartCamera:(UIButton *)sender {
   [unicoCheck setSmartFrame:true];
   [unicoCheck setAutoCapture:true];
}

Implementing Delegates for Camera Events


The camera opening method needs to know what to do when it successfully captures an image or encounters an error during the process. "What to do" is informed to the camera opening method through the configuration of delegates that are called in success or error situations.

By configuring the delegates, you can specify what happens in your app in error situations (method onErrorSelfie) or success (method onSuccessSelfie) when capturing images.

To configure the delegates, you need to implement the SelfieCameraDelegate and AcessoBioSelfieDelegate interfaces:

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

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

onSuccessSelfie Method


When successfully capturing an image, this method is invoked and returns an object of type SelfieResult, which is later used in the REST API calls.

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

The ResultCamera object returns 2 attributes: base64 and encrypted:

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

  • The encrypted attribute must be sent in the REST API calls of by Client.

onErrorSelfie Method


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

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

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

Environment Configuration


If not configured, the SDK uses the environment set through the configuration file (getHostKey). If getHostKey is not being used, an error will be returned.

It is possible to configure the environment to be used during the execution of the SDK. Use the EnvironmentEnum enumerated type, which contains the following values:

  • EnvironmentEnum.PROD: for the Production environment

  • EnvironmentEnum.UAT: for the Staging environment

See how to implement it in the example below:

[unicoCheck setEnvironment:PROD];

Prepare and Open Camera


To proceed with opening the camera, you must first prepare it using the prepareSelfieCamera method. This method takes as parameters the implementation of the SelfieCameraDelegate class and the JSON containing the credentials generated in the previous step.

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

@interface ViewController: UIViewController <AcessoBioManagerDelegate,
SelfieCameraDelegate, AcessoBioSelfieDelegate> {
    AcessoBioManager *unicoCheck;
}

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

Once the camera is prepared, the onCameraReady event is triggered and receives an object of type AcessoBioCameraOpenerDelegate as a parameter.

You should override this method and open the camera using the object received through the open() method:

- (void)onCameraReady:(id)cameraOpener {
    [cameraOpener open:self];
}

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

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

If any error occurs while preparing the camera, the onCameraFailed event is triggered. You should implement this method applying your app's business rules.

Making a POST Request to the Client API


Capturing the images is only the first part of the journey. After capturing the image, it is necessary to send the encrypted generated by the SDK to the by Client REST APIs. Learn more in the CreateProcess section of 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?