Documents capture
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.
Compatibilidad y Requisitos
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.- In Xcode, go to the “General” tab of your application's target.
- 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>
- 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.
- 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
}
}
- Implement the Protocol
The view that launches the SDK must adopt the
CaptureDocumentVCDelegateprotocol. 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.
- 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.