Importing the SDK
Remotely
Starting installation
pod init
Our SDK can be imported using CocoaPods.
| SDK | Versão atual |
|---|---|
| ZaigIosOCR | pod 'ZaigIosOCR', '~> 6.0.2' |
15.5
Currently, our OCR SDK for iOS unfortunately does not support being compiled for simulators running on a MacBook with arm64 architecture chip (M1/M2/M3/M4), unless Rosetta is used, which translates the x86_64 architecture to arm64.
To start installation, run the command above in your project's root folder.
Adding the source to the podfile
source 'https://github.com/ZaigCoding/iOS.git'
The next step is to add QI Tech's source to the podfile file.
Adding the pod to the podfile
pod 'ZaigIosOCR', '~> <version>'
Finally, just add the pod name according to the format above.
Architecture Change (v6.0.0+) Starting from version 6.0.0, the SDK is distributed exclusively in static form. In your Podfile, you must use the configuration :linkage => :static.
Podfile example (Version 6.0.0 or higher)
source 'https://github.com/ZaigCoding/iOS.git'
source 'https://cdn.cocoapods.org/'
target 'ExampleApp' do
use_frameworks! :linkage => :static
pod 'ZaigIosOCR', '~> 6.0.0'
end
post_install do |installer|
installer.pods_project.targets.each do |target|
if ['DatadogCore', 'DatadogInternal', 'DatadogCrashReporting', 'DatadogLogs'].include?(target.name)
target.build_configurations.each do |config|
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '12.0'
config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'
end
end
end
end
Podfile example (Previous Versions)
source 'https://github.com/ZaigCoding/iOS.git'
source 'https://cdn.cocoapods.org/'
target 'ExampleApp' do
use_frameworks!
pod 'ZaigIosOCR', '~> 4.0.0'
end
post_install do |installer|
installer.pods_project.targets.each do |target|
if ['DatadogCore', 'DatadogInternal', 'DatadogCrashReporting', 'DatadogLogs'].include?(target.name)
target.build_configurations.each do |config|
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '12.0'
config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'
end
end
end
end
When integrating dependencies in iOS, the need may arise to use static linking for some libraries and dynamic for others. This configuration is relevant to ensure compatibility, avoid build errors and optimize project performance.
Hybrid Dependency Linking (if necessary)
The need for hybrid linking arises because some libraries have specific requirements, with some needing static linking to avoid internal conflicts and symbol duplication and other dependencies may need dynamic linking, as they are designed for modularity and sharing between projects.
Differences Between Static and Dynamic Linking
- Static (static_framework): The library code is directly incorporated into the final binary, reducing runtime loading time and eliminating external dependencies during execution.
- Dynamic (dynamic_framework): The library is loaded at runtime as a separate file. This reduces the final binary size and facilitates independent updates/modifications.
Configuring hybrid linking in Podfile
...
use_frameworks! :linkage => :dynamic # CONFIGURANDO O MODO PADRÃO DE LINKAGEM PARA DINÂMICO
...
static_frameworks = ['framework_1', 'framework_2', ...] # INCLUIR TODAS AS DEPENDÊNCIAS QUE PRECISAM SER LINKADAS DE MODO ESTÁTICO
pre_install do |installer|
installer.pod_targets.each do |pod|
if static_frameworks.include?(pod.name)
def pod.static_framework?;
true
end
def pod.build_type;
Pod::BuildType.static_framework
end
end
end
end
Installing dependencies
pod install
Finally, run the pod install command to download and install the dependencies.
Required Permissions
For the SDK to access device resources to collect the photo, it is necessary to request permissions from the user.
In the info.plist file, add the permissions below:
| Permission | Reason |
|---|---|
| Privacy - Camera Usage Description | Camera access to capture document photos. |
Starting the SDK
import ZaigIosOcr
class ViewController: UIViewController, ZaigIosOcrControllerDelegate {
var zaigOcrConfiguration : ZaigIosOcrConfiguration?
override func viewDidLoad() {
super.viewDidLoad()
self.setupOcr()
}
func setupOcr() -> Void
{
// The environment can be 'Sandbox' ou 'Production'
let environment = ZaigIosOcrEnvironment.Sandbox
// MobileToken is the key sent to you by QI Tech. Each environment requires a different MobileToken.
let mobileToken = "YOUR_MOBILE_TOKEN_SENT_BY_QITECH"
// The documentFlow can be 'CnhFull' , 'CnhFrontAndBack' ou 'RgFrontAndBack'
let documentFlow = ZaigIosOcrDocumentFlow.CnhFrontAndBack
self.ocrConfig = ZaigIosOcrConfiguration(environment: environment,
mobileToken: mobileToken,
sessionId: "UNIQUE_SESSION_ID",
documentFlow: documentFlow,
backgroundColor: "#000000",
fontColor: "#FFFFFF",
fontFamily: .open_sans,
showIntroductionScreens: true,
logLevel: .debug
)
}
// Event where you intend to call QI Tech OCR View Controller - on this example, when the user press 'next' button
@IBAction func pressNext(_ sender: Any) {
let zaigOcrController = ZaigIosOcrController(ocrConfiguration: self.ocrConfig)
zaigOcrViewController.delegate = self
let zaigOcrViewController = zaigOcrController.getViewController()
present(zaigOcrViewController, animated: true, completion: nil)
}
// Do something if QI Tech OCR's SDK succesfully collected document picture
func zaigIosOcrController(_ ocrViewController: ZaigIosOcrController, didFinishWithResults results: ZaigIosOcrControllerResponse) {
}
// Do something if QI Tech OCR's SDK found any error when collecting document picture
func zaigIosOcrController(_ ocrViewController: ZaigIosOcrController, didFailWithError error: ZaigIosOcrControllerError) {
}
// Do something if the user canceled the picture collection on any steps
func zaigIosOcrControllerDidCancel(_ ocrViewController: ZaigIosOcrController) {
}
}
To incorporate the SDK into your application, you must configure your custom capture application through the ZaigIosOcrConfiguration class and then instantiate the ZaigIosOcrController ViewController passing the custom configurations as an argument.
To start the document analysis process, simply call the present function to call QI Tech's ViewController that will perform the image collection.
It is important to implement the Delegate responsible for receiving returns in case of success, error or if the user interrupts the journey at any stage of validation.
Above we have a complete implementation example.
Enable support for Portrait and Landscape Right orientations in your application for correct SDK operation.
Mobile Token
We use a Mobile Token to allow authenticated access from your application to our API. It has probably already been sent to you by email. If you have not yet received your token, send an email to suporte.caas@qitech.com.br.
Our API expects to receive the Mobile Token in all requests to our server coming from the SDK, therefore, it must be included as a configuration parameter through the method mentioned above.
You must replace "YOUR_MOBILE_TOKEN_SENT_BY_QITECH" with the Mobile Token received from support.