Skip to main content
MÓDULO NATIVO

Documents capture

The purpose of this document is to provide developers with a detailed guide on how to integrate and implement the DocumentCaptureUI SDK into iOS applications built with SwiftUI. This SDK enables the efficient capture of proof-of-address documents by launching the camera with a visual guide and returning the captured image's file path to the host application.

When the document capture module is invoked, the library opens the camera to begin the document capture process. A screen appears displaying the active camera view along with instructions and recommendations to optimize the photograph. Once the capture process is complete, the library returns control to the application, providing the process results.

Regresar
IOSSWIFTUIv2.1.0

Compatibilidad y Requisitos

Lenguaje
SwiftUI
OS Min
iOS 13+
Swift
5.5+
IDE
Xcode

Integrating and Signing the Framework

In Xcode, navigate to the *“General”* tab of the application target and locate the *“Frameworks, Libraries and Embedded Content”* section. For the `DocumentCaptureUI.xcframework` framework, select the “**Embed & Sign**” option from the “**Embed**” column.
  1. In Xcode, go to the “General” tab of your application's target.
  2. Under “Frameworks, Libraries and Embedded Content”, add DocumentCaptureUI.xcframework and select the “Embed & Sign” option in the “Embed” column.

Prerequisites

1. **Camera Permissions**: Add the camera usage key to the `Info.plist` file:

Info.plist

<!-- Info.plist -->
<key>NSCameraUsageDescription</key>
<string>Please grant permission to use the camera.</string>
Adjust the text to suit your desired message.
  1. Add the Framework to the Project: In the view (or SwiftUI structure) where you will launch the capture, import the module:

• Drag DocumentCaptureUI.xcframework into the project.

• Make sure to check the “Copy items if needed” box.

• Select the target(s) where you need to use it.

  1. Import the SDK: In the view (or SwiftUI structure) where you will launch the capture, import the module:

    Import

    import DocumentCaptureUI

Starting the Document Capture Process

1. **Declare the View That Invokes the SDK**: In the host application, create or modify the SwiftUI view from which you will initiate the capture. You can use a button that presents the SDK view using a `fullScreenCover` or a `sheet`. For example:

DocumentCapture.swift

import SwiftUI
import DocumentCaptureUI

struct DocumentCapture: View, CaptureDocumentVCDelegate {
// Controls camera presentation
@State private var showDocumentCapture = false

var body: some View {
VStack {
Button("Start capture") {
showDocumentCapture = true
}
}
.fullScreenCover(isPresented: $showDocumentCapture) {
// Framework view is initialized
CaptureUI(
token: "YOUR_PROVIDED_TOKEN",
urlVerify: "https://api.devdicio.net:8444/v1/sec_dev_pagos_middleware",
delegate: self
)
}
}

// MARK: - CaptureDocumentVCDelegate

/// Protocol method that receives whether the capture was successful and the image route
func pictureFinished(isSuccessfull: Bool, route: String) {
print("Successful photo? \\(isSuccessfull) route: \\(route)")
// Closes the fullScreenCover
showDocumentCapture = false

// Here you can process the image according to your business logic
}
}
Note: If your token and URL come from other sources, substitute them where appropriate.
  1. Implement the Protocol The view that launches the SDK must adopt the CaptureDocumentVCDelegate protocol. This requires you to implement the following method: • pictureFinished(isSuccessfull: Bool, route: String)

This method notifies you of the capture result: • isSuccessfull: true if the photo was saved successfully; false otherwise. • route: The path within your application's file system where the photo was saved. If an error occurs or the capture is cancelled, the path might be an empty string or a placeholder value.

  1. Complete Usage Example

Complete Example

struct DocumentCapture: View, CaptureDocumentVCDelegate {
@State private var showDocumentCapture = false

var body: some View {
VStack {
Button("Start capture") {
showDocumentCapture = true
}
}
.fullScreenCover(isPresented: $showDocumentCapture) {
CaptureUI(
token: "YOUR_PROVIDED_TOKEN",
urlVerify: "https://example.service.com",
delegate: self
)
}
}

// MARK: - CaptureDocumentVCDelegate
func pictureFinished(isSuccessfull: Bool, route: String) {
print("Successful photo? \\(isSuccessfull) route: \\(route)")
// Closes the screen
showDocumentCapture = false

// Here you can handle the route or show a message to the user.
}
}

Framework Main View Reference

Within the framework, the main view is CaptureUI. It accepts the following parameters:

• token: A string containing the provided token.

• urlVerify: A string containing the base URL used to verify the token.

• delegate: CaptureDocumentVCDelegate, used to report results.

Additional Considerations

• Error Handling: The SDK internally handles cases involving denied permissions or unauthorized tokens. If the user denies access to the camera or microphone, an alert will appear instructing them to grant the necessary permissions.

• Styling and UI: You can customize the presentation (e.g., using .sheet instead of .fullScreenCover), provided the container is a SwiftUI view.

• Integration into Existing Projects: Ensure your project supports iOS 13+ (or the minimum version you have defined). This SDK is not compatible with earlier versions.

• Versioning: Check the specific version of DocumentCaptureUI.xcframework you receive, in case there are updates or API changes.