SelphID Component
1. Introduction
Mobile SDK is a set of libraries (Components) that offers a series of functionalities and services, allowing its integration into a Mobile application in a simple, totally scalable way. Depending on the use case that is required, the installation of certain components must be carried out. Its high level of modularity allows that, in the future, other new components can be added without affecting at all those already integrated into the project.
The Component addressed in the current document is named SelphID Component. This is responsible for capturing documents and the subsequent extraction and analysis of the data obtained from them. Its main functionalities are the following:
-
Internal camera management.
-
Permissions management.
-
Assists in the processes of capturing the front and back of the document.
-
Extraction of the information contained in the document.
-
Obtaining the images of the back and reverse of the document, as well as other images included in the document: user's face, user's signature,...
-
High level of configuration: different countries, languages, types of documents...
1.1 Minimum requirements
The minimum native version (Android and iOS) of the SDK are as follows:
- Minimum Android version: 24 - JDK 17
- Minimum Build Tools version: 8.1.4
- Minimum Kotlin Android version (sdk <= 2.2.x): 1.9.0
- Minimum Kotlin Android version (sdk >= 2.3.x): 2.1.0
- Minimum iOS version: 13
- Minimum Cordova Android version: 12.0.0
- Minimum Cordova iOS version: 7.0.0
Regarding the architecture of the mobile device:
- armeabi-v7, x86, arm64 and x64
1.2 Plugin version
The current plugin version can be checked as follows:
-
We look for the package.json file at the root of the plugin.
-
The KEY/TAG version indicates the version.
2. Component integration
Before integrating this component, it is recommended to read the documentation related to Core Component and follow the instructions indicated in said document.
ℹ️ For this section, the following values will be considered:
-
<%APPLICATION_PATH%> - Path to the root of the application (example: /folder/example)
-
<%PLUGIN_CORE_PATH%> - Path to the root of the core plugin, which is mandatory (example: /folder/sdk-core)
-
<%PLUGIN_SELPHID_PATH%> - Path to the root of the current plugin (example: /folder/sdk-selphid)
2.1. Plugin installation: Common
The plugin allows execution on Android and iOS platforms. This section explains the common steps to all platforms. To install the plugin, the following steps must be adopted:
- Make sure Cordova is installed.
- Access <%APPLICATION_PATH%> at a terminal and run:
cordova plugin add @facephi/sdk-core-cordova
cordova plugin add @facephi/sdk-selphid-cordova
yarn install
- In addition, to install the plugin on iOS, the following must also be executed:
cd ios
pod install
- It is important to verify that the path to the plugin is correctly defined in package.json:
"dependencies": {
"sdk-core-cordova": <% PLUGIN_CORE_PATH %>,
"sdk-selphid-cordova": <% PLUGIN_SELPHID_PATH %>
}
After running the above steps, you can start the app with the sdk/component installed.
- Finally, to launch the projects, the following commands must be executed in two ways:
From Terminal
cordova plugin ls
From different IDEs
Projects generated in the Android and iOS folders can be opened, compiled, and debugged using Android Studio and XCode respectively.
2.2 Plugin installation: iOS
2.2.1 Project configuration
For the iOS version, when adding our plugin to the final application, the following points must be previously taken into account:
- Add camera permissions: To use the widget, you need to enable the camera permission in the application's info.plist file (included within the project in the ios folder). You will need to edit the file with a text editor and add the following key/value pair:
<key> NSCameraUsageDescription </key>
<string>$(PRODUCT_NAME) uses the camera</string>
2.2.2 Podfile Update
In the project podfile it will be necessary to add the information from the private repository (see section 2.1). To do this, the following lines must be added at the beginning of the file:
platform :ios, '13.0' //MIN VERSION
plugin 'cocoapods-art', :sources => ['cocoa-pro-fphi']
source 'https://cdn.cocoapods.org/'
ℹ️ To know more about the configuration and use of Cocoapods Artifactory, it is necessary to access the following document of Core Component.
2.2.4 Possible issues
If environmental problems occur or the plugin is not updated after making new changes (for example, problems occurred due to the bundle not being generated correctly, or the libraries not being updated to the correct versions), it is recommended to execute the following sequence of instructions after launching the plugin:
-
Open the application's ios folder at a terminal.
-
Run the following command:
pod deintegrate
-
Remove the Podfile.lock
-
Run the following command (or open the project with Xcode and run it):
pod install --repo-update
2.3 Plugin installation: Android
2.3.1 Set Android SDK version
For Android, the minimum SDK version required by our native libraries is 24, so if your app has a Minimum SDK defined less than this, it will need to be modified to avoid a compile error. To do this, access the application's build.gradle file (located in the android folder) and modify the following parameter:
buildscript {
ext {
minSdkVersion = 24
}
}
2.3.2 Permissions for geolocation
Because the Tracking component has geolocation options, it is necessary to add the permissions for it. In the AndroidManifest add the following permissions:
<!-- Always include this permission -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<!-- Include only if your app benefits from precise location access. -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
3. Component configuration
The current component contains a number of Typescript methods and interfaces contained within the plugins/com.facephi.sdk.selphid/www/ file. ** In this file you can find the necessary API for the communication between the application and the native functionality of the component. It is then explained what each one of those listed is for and the other properties that affect the operation of the component.
The following is the SelphIDConfiguration class, which allows you to configure the SelphID component:
export interface SelphidConfiguration {
debug?: boolean;
fullScreen?: boolean;
frontalCameraPreferred?: boolean;
tokenImageQuality?: number;
timeout?: SelphIDTimeout;
showResultAfterCapture?: boolean;
showTutorial?: boolean;
tutorialOnly?: boolean;
scanMode?: string;
specificData?: string;
documentType?: string;
videoFilename?: string;
fullscreen?: boolean;
documentModels?: string;
enableWidgetEventListener?: boolean;
generateRawImages?: boolean;
translationsContent?: string;
viewsContent?: string;
cameraId?: number;
params?: any;
resourcesPath?: string;
tokenPrevCaptureData?: string;
wizardMode?: boolean;
documentSide?: string;
showDiagnostic?: boolean;
compressFormat?: SdkCompressFormat,
imageQuality?: number,
}
Then, all the properties that can be defined in the SelphidConfiguration object will be commented on:
ℹ️ All the configuration can be found in the component's src/index.tsx file.
When making the call to the widget there is a series of parameters that must be included. They will be briefly discussed below.
3.1 resourcesPath
type: string
Sets the name of the resource file that the widget will use for its graphical configuration. This file is customisable and is located in the plugin in the src/main/assets folder for Android and in the ios/Frameworks and Resources folder for iOS. Its installation is transparent to the user, it will simply be added to the respective platform's projects during plugin installation. More details about how this resource pack works and how to modify it are explained in section 6.
resourcesPath: "fphi-selphid-widget-resources-sdk.zip"
3.2 ShowResultAfterCapture
type: boolean
Indicates whether or not to display a screen with the captured image of the document after the analysis process. This screen gives the user the option of repeating the capture process if the image obtained from the document is not correct.
showResultAfterCapture: false
3.3 ScanMode
type: WidgetScanMode
This enumeration is defined in the SdkSelphidEnum.tsx class. Indicates the OCR scanning mode of the documents. Depending on the choice, several types of documents or one in particular will be scanned and searched. This mode can be of three types:
-
SelphIDScanMode.Generic: The generic mode that allows you to scan any type of document regardless of the country or the type of document. The result of this mode is not as accurate as the following, but it allows you to scan various standard documents.
-
SelphIDScanMode.Search: The search mode will allow you to use a whitelist and blacklist, and will search the documents that meet those conditions. These conditions are specified in the "specificData" variable. In this way it is possible to carry out the search limiting the number of templates, and making the search much more refined than in the generic case.
-
SelphIDScanMode.Specific: Search for a specific document. These conditions are indicated in the "specificData" property shown below.
scanMode: SdkSelphidEnums.SdkScanMode.Search;
3.4 SpecificData
type: string
This property allows you to define which documents will be scanned during the process in the event of declaring the scan mode (scanMode) to GenericMode, SpecificMode or SearchMode.
An example of a configuration that allows all documents of Spanish nationality to be scanned would be the following:
scanMode: WidgetScanMode.Search;
specificData: “ES|<ALL>”; // Spanish ISO code(ES)
3.5 FullScreen
type: boolean
Determines whether you wish the widget to start in full screen mode, hiding the status bar.
fullscreen: true;
3.7 DocumentType
type: string
This enumeration is defined in the SdkSelphidEnums.tsx class. Specified in the *WidgetDocumentType class:
-
IDCard: Establishes that identity documents or cards will be captured.
-
Passport: Establishes that passports will be captured. (Additionally, the scanMode will have to be set to SelphIDScanMode.Generic).
-
DriverLicence: Establishes that driver's licences will be captured.
-
ForeignCard: It establishes that Foreigners' identity cards will be captured.
-
Custom: Includes documents that are not in any of the above categories.
documentType: SdkSelphidEnums.SdkDocumentType.IDCard;
3.8 TokenImageQuality
type: double
Specifies the compression quality of the tokenFaceImage.
Indicates whether the sdk returns to the application the images used during extraction or not. It should be noted that returning images can result in a significant increase in device resource usage:
tokenFaceImage: 0.9;
3.9 generateRawImages
type: boolean
This property configures the widget to return the full image from the camera that was used to capture the document:
- rawFrontDocument: Front image of the raw document.
- rawBackDocument: Rear image of the raw document.
- tokenRawFrontDocument: Tokenisation of the front image of the raw document.
- tokenRawBackDocument: Tokenisation of the rear image of the raw document.
generateRawImages: true;**
3.10 timeout
type: SelphIDTimeout
It is an enumerator that defines the timeout of the capture of one side of the document. It has 4 possible values:
- SelphIDTimeout.Short: 15 segundos.
- SelphIDTimeout.Medium: 20 segundos.
- SelphIDTimeout.Long: 25 segundos.
- SelphIDTimeout.VeryLong: 60 segundos.
3.11 tutorialOnly
type: boolean
Establishes whether you wish to launch the widget in Tutorial mode. This allows you to show the previous widget tutorial, but WITHOUT performing the post capture process. Useful if you wish to show the tutorial in isolation.
tutorialOnly: true;
3.12 videoFilename
type: string
⚠️ This is an advanced property, and in most use cases you don't need to modify it. Incorrect use may cause component malfunction.
This is an advanced property, and in most cases you don't need to modify it. Incorrect use may cause component malfunction.
Sets the absolute path of the file name in which a video of the capture process will be recorded. The application is responsible for requesting the necessary permissions to the phone in case that route requires additional permissions. The component, by default, will not perform any write processing unless a file path is specified using this method.
videoFilename: “<videofile-path>“;
3.13 documentModels
type: string
⚠️ This is an advanced property, and in most use cases you don't need to modify it. Incorrect use may cause component malfunction.
This is an advanced property, and in most use cases you don't need to modify it. Incorrect use may cause component malfunction.
This property allows, through a string in xml format, to configure the modelling of the documents that the widget will try to capture. The definition of this modelling can be found, by default, in .xml models within the resources .zip. With this property an application is allowed to update and replace, in execution, the models of the current documents of the component.
documentModels: “<document-models-content-string>“;
3.14 translationsContent
type: string
⚠️ This is an advanced property, and in most use cases you don't need to modify it. Incorrect use may cause component malfunction.
This is an advanced property, and in most use cases you don't need to modify it. Incorrect use may cause component malfunction.
This property allows, through a string in xml format, to configure the current location of the widget. The definition of this model can be found, by default, in an internal translations folder within the resources .zip. This property allows an application to update and replace the current location of the component at run time.
translationsContent: “<translation-content-string>