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 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.

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 with the relevant context and override the callback methods with your application’s business logic:

.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


As shown in the previous example, the main task when implementing the AcessoBioManagerDelegate interface is configuring the callback methods. Each method is called in response to a specific return from the SDK.

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

1

onErrorAcessoBioManager(_ error: ErrorBio!)

This method is invoked whenever any implementation error occurs using any SDK method. It receives an ErrorBio parameter that contains error details. See the Error Handling section for more about ErrorBio.

2

onUserClosedCameraManually()

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

3

onSystemClosedCameraTimeoutSession()

This method is invoked when the maximum session time is reached (without capturing an image).

You can configure the session timeout in seconds using setTimeoutSession. The default and minimum timeout is 40 seconds.

4

onSystemChangedTypeCameraTimeoutFaceInference()

This method is invoked when the maximum time for face detection is reached without detection.

The maximum time is 13 seconds. The mode is then switched to manual capture to facilitate the user’s action.

All the above methods must be created as indicated in your project (even without any logic); otherwise, the project won’t compile successfully.

Configuring Camera Mode


The SDK is preconfigured with intelligent framing and automatic capture. Configure the camera mode in the builder as follows:

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

The false/true values in the above methods do not alter the capture experience; they are solely used for the SDK's internal logic.

Implementing Delegates for Camera Events


The camera launch method needs to know how to handle situations when an image is successfully captured or when an error occurs during the process. The handling instructions are passed to the camera launch method by setting delegates, which are called in cases of success or error.

Through delegate configuration, you can specify what actions your app should take in the event of an error (using the onErrorSelfie method) or success (using the onSuccessSelfie method) in capturing images.

To set up the delegates, you must 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


Upon successful image capture, this method returns a SelfieResult object for subsequent API requests:

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

The SelfieResult object provides two attributes: base64 and encrypted:

  • Use base64 for preview in the app;

  • Use encrypted for sending to REST APIs.

  • The encrypted attribute is strictly intended for sending the image through the by Client APIs. It should not be opened or serialized, as its characteristics may change without prior notice. Its use must be exclusive to interactions with the APIs to ensure the integrity and security of the data. Unico is not responsible for any damages arising from this practice, as modifications may occur unexpectedly.

  • The base64 and encrypted files can vary in size due to several factors, including the quality of the devices and the photos generated, as well as Unico's business rules. To avoid issues in your application, do not restrict the size of the string generated by the SDK for these files in your programming logic or infrastructure.

If it is necessary to convert the base64 string to a bitmap, the standard method does not work for Android. You need to perform a split at the comma (,) for it to function correctly. If you want to learn more, read the article:How to convert a Base64 string into a Bitmap image to show it in a ImageView?.

onErrorSelfie Method


If an error occurs during image capture, this method returns an ErrorBio object:

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

Learn more about ErrorBio types in the SDK Error Handling section.

Environment Configuration


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

You can configure the environment to be used during SDK execution by using the EnvironmentEnum enumeration, which contains the following options:

  • EnvironmentEnum.PROD: for the Production environment

  • EnvironmentEnum.UAT: for the Testing (UAT) environment

See the implementation 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 two parameters: the implementation of the SelfieCameraDelegate 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,
SelfieCameraDelegate, AcessoBioSelfieDelegate> {
    AcessoBioManager *unicoCheck;
}

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

When the camera is prepared, the onCameraReady event is triggered, receiving an object of type AcessoBioCameraOpenerDelegate as a parameter. You should override this method to 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 ErrorPrepare type is an extension of ErrorBio, containing all of its properties. Learn more about the ErrorBio type in the SDK error handling section.

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

Making a POST Request to the Client API


After capturing images, the next step is to send the generated encrypted image from the SDK to the Client APIs.

For security reasons, the interval between the generation of the encrypted data and the sending through one of the available flows must be no more than 10 minutes. Submissions made beyond this period will be automatically rejected by the API.


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.

Atualizado

Institucional

Sobre nós

Copyright © 2024 unico. All rights reserved