Initialization
Initializing Veryfi Lens is a critical step in utilizing its capabilities within your mobile application. In this section, we'll provide detailed instructions on how to correctly initialize Veryfi Lens for every platform.
- iOS
- Android
- Capacitor
- React Native
- Flutter
- .NET
1. Import the Lens SDK:
import VeryfiLens
2. Configure your authentication credentials:
Please refer to
section to obtain credentialsEnsure that you
and do not expose or store them in your application's source code or publicly accessible locations.let CLIENT_ID = "XXX" // replace XXX with your assigned Client Id
let AUTH_USERNAME = "XXX" // replace XXX with your assigned Username
let AUTH_APIKEY = "XXX" // replace XXX with your assigned API Key
let URL = "XXX" // replace XXX with your assigned Endpoint URL
let veryfiLensCredentials = VeryfiLensCredentials(clientId: CLIENT_ID,
username: AUTH_USERNAME,
apiKey: AUTH_APIKEY,
url: URL)
3. Configure your Veryfi Lens Settings.
The full list available Veryfi Lens Settings is available in the
sectionlet veryfiLensSettings = VeryfiLensSettings()
veryfiLensSettings.autoCaptureIsOn = true
veryfiLensSettings.autoRotateIsOn = true
veryfiLensSettings.dataExtractionEngine = .inApp
veryfiLensSettings.documentTypes = ['barcode']
veryfiLensSettings.galleryIsOn = false
veryfiLensSettings.moreMenuIsOn = false
4. Initialize Lens:
VeryfiLens.shared().configure(with: veryfiLensCredentials, settings: veryfiLensSettings) { success in
if success {
// Start using lens
}
}
5. Enable background upload support. Add the code below to your AppDelegate:
import AWSS3
func application(_ application: UIApplication, handleEventsForBackgroundURLSession identifier: String, completionHandler: @escaping () -> Void) {
// Store the completion handler
AWSS3TransferUtility.interceptApplication(application, handleEventsForBackgroundURLSession: identifier, completionHandler: completionHandler)
}
1. Import required classes from Lens SDK
import com.veryfi.lens.VeryfiLens
import com.veryfi.lens.VeryfiLensCredentials
import com.veryfi.lens.VeryfiLensSettings
import com.veryfi.lens.VeryfiLensDelegate
2. Configure your authentication credentials
Please refer to
section to obtain credentialsEnsure that you
and do not expose or store them in your application's source code or publicly accessible locations.val veryfiLensCredentials = VeryfiLensCredentials()
veryfiLensCredentials.clientId = "XXX" // replace XXX with your assigned Client Id
veryfiLensCredentials.username = "XXX" // replace XXX with your assigned Username
veryfiLensCredentials.apiKey = "XXX" // replace XXX with your assigned API Key
veryfiLensCredentials.url = "XXX" // replace XXX with your assigned Endpoint URL
3. Configure your Veryfi Lens settings.
The full list available Veryfi Lens Settings is available in the
sectionval veryfiLensSettings = VeryfiLensSettings()
veryfiLensSettings.autoCaptureIsOn = true
veryfiLensSettings.autoRotateIsOn = true
veryfiLensSettings.autoSubmitDocumentOnCapture = true
veryfiLensSettings.documentTypes = arrayListOf(DocumentType.BARCODES)
veryfiLensSettings.galleryIsOn = false
veryfiLensSettings.moreMenuIsOn = false
4. Initialize Lens:
VeryfiLens.configure(this, veryfiLensCredentials, veryfiLensSettings)
1. Import required symbols from Lens SDK:
import '@veryfi/veryfi-lens-capacitor'
import { VeryfiLensCapacitor } from '@veryfi/veryfi-lens-capacitor'
2. Configure your authentication credentials:
Please refer to
section to to obtain credentials.Ensure that you keep these credentials secure and do not expose or store them in your application's source code or publicly accessible locations.
const veryfiLensCredentials = {
clientId: 'XXXX', // replace XXXX with your assigned Client Id
userName: 'XXXX', // replace XXXX with your assigned Username
apiKey: 'XXXX', // replace XXXX with your assigned API Key
url: 'XXXX', // replace XXXX with your assigned Endpoint URL
}
3. Configure your Lens settings:
The full list available Veryfi Lens Settings is available in the
sectionconst veryfiLensSettings = {
blurDetectionIsOn: true,
autoLightDetectionIsOn: false,
dataExtractionEngine: 1,
documentTypes: ['barcode'],
}
4. Initialize Lens:
const options = {
credentials: veryfiLensCredentials,
settings: veryfiLensSettings,
}
VeryfiLensCapacitor.veryfiInitLens(options)
1. Import Veryfi Lens SDK
import VeryfiLens from '@veryfi/react-native-veryfi-lens'
2. Configure your authentication credentials:
Please refer to
section to obtain credentialsEnsure that you
and do not expose or store them in your application's source code or publicly accessible locations.const veryfiLensCredentials = {
url: 'XXX', // replace XXX with your assigned Endpoint URL
clientId: 'XXX', // replace XXX with your assigned Client ID
userName: 'XXX', // replace XXX with your assigned Username
apiKey: 'XXX', // replace XXX with your assigned API Key
}
3. Configure your Lens settings. Refer to the full list of available settings later in this section.
The full list available Veryfi Lens Settings is available in the
sectionconst veryfiLensSettings = {
blurDetectionIsOn: true,
autoLightDetectionIsOn: false,
backupDocsToGallery: true,
autoDocDetectionAndCropIsOn: true,
showDocumentTypes: true,
dataExtractionEngine: 1,
documentTypes: ['barcode'],
moreMenuIsOn: true,
originalImageMaxSize: 2.0,
stitchedPDFPixelDensityMultiplier: 2.0,
}
4. Initialize Lens. Send the above credentials and settings to Lens. Without this, Lens will fail to authenticate and launch.
VeryfiLens.configureWithCredentials(
veryfiLensCredentials,
veryfiLensSettings,
() => {
// In here you'll want to use one of the available options
// ex. showCamera, showGallery...
}
)
If you are developing a new Flutter project, consider initializing the Veryfi Lens SDK in the main.dart
file.
1. Import Veryfi Lens SDK
import 'package:veryfi/lens.dart';
2.Configure your authentication credentials:
Please refer to
section to obtain credentialsEnsure that you
and do not expose or store them in your application's source code or publicly accessible locations.Map<String, dynamic> credentials = {
'clientId': 'XXXX', // replace XXX with your assigned Client Id
'userName': 'XXXX', // replace XXX with your assigned Username
'apiKey': 'XXXX', // replace XXX with your assigned API Key
'url': 'XXXX' // replace XXX with your assigned Endpoint URL
};
3. Configure your Lens settings. Refer to the full list of available settings later in this section.
The full list available Veryfi Lens Settings is available in the
sectionMap<String, dynamic> settings = {
'dataExtractionEngine': 1,
'documentTypes': ['barcode'],
'showDocumentTypes': true
};
Initialize Lens:
try {
Veryfi.initLens(credentials, settings);
} on Exception catch (e) {
// Handle initLens exception here
}
- .NET iOS Project
- .NET Android Project
1. Import Veryfi Lens .NET SDK
Add these imports to the top of your .cs
file
using VeryfiLensiOS;
2. Configure your authentication credentials:
Please refer to
section to obtain credentialsEnsure that you
and do not expose or store them in your application's source code or publicly accessible locations.const String CLIENT_ID = "XXX"; // replace XXX with your assigned Client Id
const String USERNAME = "XXX"; // replace XXX with your assigned Username
const String API_KEY = "XXX"; // replace XXX with your assigned API Key
const String URL = "XXX"; // replace XXX with your assigned Endpoint URL
var veryfiLensCredentials = new VeryfiLensCredentials
{
ClientId = CLIENT_ID,
Username = USERNAME,
ApiKey = API_KEY,
Url = URL
};
3. Configure your Veryfi Lens settings. Refer to the full list of available settings later in this section.
The full list available Veryfi Lens Settings is available in the
sectionVeryfiLensSettings veryfiLensSettings = new VeryfiLensSettings
{
AutoLightDetectionIsOn = false,
BlurDetectionIsOn = true,
DocumentTypes = new List<DocumentType> { DocumentType.Receipt },
ShowDocumentTypes = true
};
4. Initialize Lens:
Learn more about the Veryfi Lens Public Public Interface in the
section- Configure Veryfi Lens SDK with credentials and settings:
Action<bool> completion = (success) => {
if (success) {
DispatchQueue.MainQueue.DispatchAsync(() => {
// Start using Lens
// ex. VeryfiLens.Shared.ShowCameraIn(this);
});
}
};
VeryfiLens.Shared.ConfigureWith(veryfiLensCredentials, veryfiLensSettings, completion);
- Set the Delegate:
VeryfiLens.SetDelegate(new VeryfiLensDelegateListener(this));
- Show Camera:
VeryfiLens.Shared.ShowCameraIn(this);
Implementation Example
You can find the minimal required implementation down below
using CoreFoundation;
using VeryfiLensiOS;
namespace iOSVeryfiTestApp;
public partial class ViewController : UIViewController
{
const string CLIENT_ID = "XXXX"; //Replace with your clientId
const string AUTH_USRNE = "XXXX"; //Replace with your username
const string AUTH_API_K = "XXXX"; //Replace with your apiKey
const string API_URL = "XXXX"; //Replace with your url
VeryfiLensDelegateListener _veryfiLensDelegate;
public ViewController() : base(nameof(ViewController), null)
{
}
public ViewController(IntPtr handle) : base(handle)
{
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
this.ShowLogs("Configuring Lens");
SetUpVeryfiLens();
SetUpVeryfiLensDelegate();
}
partial void OpenLens(NSObject sender)
{
VeryfiLens.Shared.ShowCameraIn(this);
}
private void SetUpVeryfiLensDelegate()
{
_veryfiLensDelegate = new VeryfiLensDelegateListener(this);
VeryfiLens.Shared.Delegate = _veryfiLensDelegate;
}
private void SetUpVeryfiLens()
{
VeryfiLensSettings veryfiLensSettings = new VeryfiLensSettings
{
AutoLightDetectionIsOn = false,
BlurDetectionIsOn = true,
DocumentTypes = new List<DocumentType> { DocumentType.Receipt },
ShowDocumentTypes = true
};
var veryfiLensCredentials = new VeryfiLensCredentials(CLIENT_ID, AUTH_USRNE, AUTH_API_K, API_URL);
Action<bool> completion = (success) =>
{
if (success)
{
DispatchQueue.MainQueue.DispatchAsync(() =>
{
this.ShowLogs("Lens configured");
});
}
};
VeryfiLens.Shared.ConfigureWith(veryfiLensCredentials, veryfiLensSettings, completion);
}
private void ShowLogs(string log)
{
var text = Logs.Text + log + "\n";
Logs.Text = text;
}
private class VeryfiLensDelegateListener : VeryfiLensDelegate
{
private ViewController viewController;
public VeryfiLensDelegateListener(ViewController viewController)
{
this.viewController = viewController;
}
public override void VeryfiLensClose(NSDictionary<NSString, NSObject> json)
{
viewController.ShowLogs(json.ToString());
}
public override void VeryfiLensError(NSDictionary<NSString, NSObject> json)
{
viewController.ShowLogs(json.ToString());
}
public override void VeryfiLensSuccess(NSDictionary<NSString, NSObject> json)
{
viewController.ShowLogs(json.ToString());
}
public override void VeryfiLensUpdate(NSDictionary<NSString, NSObject> json)
{
viewController.ShowLogs(json.ToString());
}
}
}
1. Import Veryfi Lens .NET SDK
Add these imports to the top of your .cs
file
using Com.Veryfi.Lens;
using Com.Veryfi.Lens.Helpers;
using Org.Json;
2. Configure your authentication credentials:
Please refer to
section to obtain credentialsEnsure that you
and do not expose or store them in your application's source code or publicly accessible locations.const String CLIENT_ID = "XXX"; // replace XXX with your assigned Client Id
const String USERNAME = "XXX"; // replace XXX with your assigned Username
const String API_KEY = "XXX"; // replace XXX with your assigned API Key
const String URL = "XXX"; // replace XXX with your assigned Endpoint URL
var veryfiLensCredentials = new VeryfiLensCredentials
{
ClientId = CLIENT_ID,
Username = USERNAME,
ApiKey = API_KEY,
Url = URL
};
3. Configure your Veryfi Lens settings. Refer to the full list of available settings later in this section.
The full list available Veryfi Lens Settings is available in the
sectionVeryfiLensSettings veryfiLensSettings = new VeryfiLensSettings
{
AutoLightDetectionIsOn = false,
BlurDetectionIsOn = true,
DocumentTypes = new List<DocumentType> { DocumentType.Receipt },
ShowDocumentTypes = true
};
4. Initialize Lens:
Learn more about the Veryfi Lens Public Public Interface in the
section- Configure Veryfi Lens SDK with credentials and settings:
VeryfiLens.Configure(Application, veryfiLensCredentials, veryfiLensSettings);
- Set the Delegate:
VeryfiLens.SetDelegate(new VeryfiLensDelegateListener());
- Show Camera:
VeryfiLens.ShowCamera();
Implementation Example
You can find the minimal required implementation down below
namespace LensAndroidTest;
using Com.Veryfi.Lens;
using Com.Veryfi.Lens.Helpers;
using Org.Json;
[Activity(Label = "@string/app_name", MainLauncher = true)]
public class MainActivity : Activity
{
protected override void OnCreate(Bundle? savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.activity_main);
const String CLIENT_ID = "XXX"; // replace XXX with your assigned Client Id
const String USERNAME = "XXX"; // replace XXX with your assigned Username
const String API_KEY = "XXX"; // replace XXX with your assigned API Key
const String URL = "XXX"; // replace XXX with your assigned Endpoint URL
var veryfiLensCredentials = new VeryfiLensCredentials
{
ClientId = CLIENT_ID,
Username = USERNAME,
ApiKey = API_KEY,
Url = URL
};
VeryfiLensSettings veryfiLensSettings = new VeryfiLensSettings
{
AutoLightDetectionIsOn = false,
BlurDetectionIsOn = true,
DocumentTypes = new List<DocumentType> { DocumentType.Receipt },
ShowDocumentTypes = true
};
VeryfiLens.Configure(Application, veryfiLensCredentials, veryfiLensSettings);
VeryfiLens.SetDelegate(new VeryfiLensDelegateListener());
VeryfiLens.ShowCamera();
}
private class VeryfiLensDelegateListener : Java.Lang.Object, IVeryfiLensDelegate
{
public void VeryfiLensClose(JSONObject json)
{
Console.WriteLine(json.ToString());
}
public void VeryfiLensError(JSONObject json)
{
Console.WriteLine(json.ToString());
}
public void VeryfiLensSuccess(JSONObject json)
{
Console.WriteLine(json.ToString());
}
public void VeryfiLensUpdate(JSONObject json)
{
Console.WriteLine(json.ToString());
}
}
}