Skip to main content

Communication

Upload a document and get instant results. Gain a deeper understanding of how Veryfi Lens interacts with your application.

Download on theApp StoreDownload on theGoogle Play

  1. Set your delegate:
VeryfiLens.shared().delegate = self
  1. Implement the delegate methods:
extension ViewController: VeryfiLensDelegate {

func veryfiLensClose(_ json: [String : Any]) {
let jsonData = try? JSONSerialization.data(withJSONObject: json as Any, options: .prettyPrinted)
let jsonString = String(data: jsonData!, encoding: .utf8)
print(String("veryfiLensClose: " + jsonString!)) // do something with the JSON here
}

func veryfiLensUpdate(_ json: [String : Any]) {
let jsonData = try? JSONSerialization.data(withJSONObject: json as Any, options: .prettyPrinted)
let jsonString = String(data: jsonData!, encoding: .utf8)
print(String("veryfiLensUpdate: " + jsonString!)) // do something with the JSON here
}

func veryfiLensSuccess(_ json: [String : Any]) {
let jsonData = try? JSONSerialization.data(withJSONObject: json as Any, options: .prettyPrinted)
let jsonString = String(data: jsonData!, encoding: .utf8)
print(String("veryfiLensSuccess: " + jsonString!)) // do something with the JSON here
}

func veryfiLensError(_ json: [String : Any]) {
let jsonData = try? JSONSerialization.data(withJSONObject: json as Any, options: .prettyPrinted)
let jsonString = String(data: jsonData!, encoding: .utf8)
print(String("veryfiLensError: " + jsonString!)) // do something with the error JSON here
}

Note: If your project is using Swift 6 add @preconcurrency keyword to your delegate implementation like this:​

extension ViewController: @preconcurrency VeryfiLensDelegate {
//... Delegate methods implementation
}

Delegate Definitions​

  • veryfiLensClose - the Veryfi Lens camera has been closed, either as a result of submitting an image for processing, or the user closed the camera without submitting an image.
{
"status": "close",
"queue_count": 1,
"framework-version": "1.4.0",
"session_scan_count": 1,
"framework-build": "1"
}

NOTE: In the object above, queue_count refers to the number of submitted documents that are currently in the processing queue. session_scan_count refers to the number of documents that were submitted in the most recent Lens camera session - if this is equal to 0 (zero) then the camera session was canceled without submitting anything.

  • veryfiLensUpdate - during the processing of a document, this delegate will be fired multiple times. One time it will contain the thumbnail path for the submitted document and one time it will contain a full-size image path. In addition, multiple instances of this delegate will be fired containing the current upload progress percentage.

Sample package created notification:

{
"status": "start",
"package_id": "edc8653e4c2b4ef1"
}

Submit was pressed while submitWithoutClose is enabled​

{
"status" : "update",
"msg" : "submit_without_close"
}

Thumbnail shared example:​

{
"status": "inprogress",
"msg": "img_thumbnail_path",
"data": "/path/to/thumbnail.jpg",
"package_id": "edc8653e4c2b4ef1"
}

Full-size image shared example:​

{
"status": "inprogress",
"msg": "img_original_path",
"data": "/path/to/image.jpg",
"package_id": "edc8653e4c2b4ef1",
"document_type": "receipt"
}

Stitched PDF shared example:​

{
"status": "inprogress",
"msg": "img_stitched_pdf_path",
"data": "/path/to/images.pdf",
"package_id": "edc8653e4c2b4ef1"
}

Upload progress example:​

{
"status": "inprogress",
"msg": "progress",
"data": 68,
"package_id": "edc8653e4c2b4ef1"
}

Package removed example:​

{
"status": "removed",
"msg": "clear_package",
"package_id": "edc8653e4c2b4ef1"
}
  • veryfiLensError - if an error occurs during uploading or processing a submitted or a general exception or crash is caught in Veryfi Lens, this notification contains the error details.

Sample error data:

{
"status": "error",
"package_id": "edc8653e4c2b4ef1",
"error": "[Wombat].Reachability.noInternetConnection"
}

Failed:​

{
"status": "fail",
"msg": "invalid_pdf_file"
}

Blurred image (when nonInteractiveBlurCheckIsOn is enabled, for uploadImages function call):​

{
"status": "failed",
"msg": "blurred_image"
}

Configuration error:​

Delivered when Lens cannot run as configured: the Veryfi server rejected the client during validation, or the SDK was used before configure was called. The msg field is a stable snake_case value you can branch on, and data.reason carries the original, unlocalized text from the server or the SDK.

{
"status": "configurationError",
"msg": "lens_not_enabled",
"data": {
"reason": "Lens not enabled for this client"
}
}

Possible msg values:

msgdata.reason (server or SDK text)
lens_not_enabledLens not enabled for this client
failed_to_get_temporary_credentialsFailed to get temporary credentials
app_not_authorizedApp not authorized for this client
failed_to_sign_validate_client_responseFailed to sign validate-client response
incorrect_authentication_credentialsIncorrect authentication credentials
api_key_not_permittedThis API key is not permitted to access this route
request_body_too_largeRequest body too large
rate_limitedYou have been rate limited
malformed_parametersMalformed parameters
client_closed_requestClient closed request / lost connection
method_not_allowedMethod "GET" not allowed. (the HTTP method name varies)
json_parse_errorJSON parse error - <details> (the details vary)
validation_failedAny other text returned by the server that is not listed above
accessing_before_configureVeryfiLens is not configured. Please call VeryfiLens.share().configure(...) to initialise VeryfiLens
info

When the server rejects the client, Lens fails closed: it does not use a previously cached validation and does not retry. If no camera is on screen to explain the error (for example uploadImages, headless usage, or configure alone), veryfiLensError is followed by veryfiLensClose, whose msg carries the same value. If the camera is visible, it shows an "Access Denied" alert instead and closes from it.

  • veryfiLensSuccess - this delegate fires once a document has finished processing, whether it was submitted via the camera, the gallery, or it was dictated or entered/typed manually. This delegate provides the response from the Veryfi API.

Example:​

{
"package_id": "edc8653e4c2b4ef1",
"data": { "address": "", "email": "dmitry@veryfi.com", "fax": "", "id": 74506, "img_url": "https://cdn.veryfi.com/image", "logo_url": "", "mobile": "", "organization": "VERYFI", "parsed_address": {}, "parsed_name": { "given_name": "Dmitry", "family_name": "Birulia" }, "person": "Dmitry Birulia", "phone": "", "text": "Dmitry Birulia dmitry@veryfi.com VERYFIwww.veryfi.com", "title": "", "web": "www.veryfi.com" }
}
  • (Optional) onHelpButtonClicked - triggered when the user taps the help button in the camera interface. This delegate method provides a presentingViewController parameter that you can use to present your custom help UI on top of the camera. You are responsible for handling the presentation and dismissal of your custom view. The help button can be enabled using the showHelpButton setting.

Example implementation:​
func onHelpButtonClicked(_ presentingViewController: UIViewController) {

let viewController = UIViewController() // Reference your custom UIViewController in here, by it a Storyboard, xib, programatic or SwiftUI UIHostingController

presentingViewController.present(viewController, animated: true)
}