SDK Initialization
Initializing PensaSdk
Developing with SwiftUI framework
Import the PensaSdk framework in your app's main struct and call the initPensa() method with PensaConfiguration.Builder() as shown below.
import SwiftUI
import PensaSdk
@main
struct SampleApp: App {
init() {
let config = PensaConfiguration.Builder()
.setClientId("YOUR_CLIENT_ID")
.setClientSecret("YOUR_CLIENT_SECRET")
.build()
Pensa.shared.initPensa(config: config) { error in
if let error = error {
print("Error initializing Pensa SDK: \(error)")
} else {
print("Pensa SDK is ready to start!!")
}
}
}
var body: some Scene {
WindowGroup {
ContentView()
}
}
}setClientId() and setClientSecret() must be provided in PensaConfiguration.Build()
If either of them is missing, .build() will throw an exception.
Developing with UIKit
Import the PensaSdk framework in your app's AppDelegate class and call initPensa() with PensaConfiguration.Builder() method inside the didFinishLaunchingWithOptions method.
setClientId() and setClientSecret() must be provided in PensaConfiguration.Build()
If either of them is missing, .build() will throw an exception.
Logging
You can show/hide Pensa framework logs by simply calling the setLoggingEnabled(true)/setLoggingEnabled(false) methods with PensaConfiguration.Builder(). By default the Pensa library logs are disabled.
Listeners
To receive real-time updates from the SDK, you can assign custom listeners using the set listener methods inside PensaConfiguration.Builder().
Listener List
.setScanUploadListener()Track scan upload progress with
onScanUploadProgressUpdate()Get notified when a scan upload is completed successfully with
onScanUploadCompleted()Get notified when a scan upload is failed with
onScanUploadFailed()
.setCantScanEventListener()Handle situations where a scan cannot be performed with
onCantScanReported()
Once the Pensa SDK is initialized, the callback method triggers immediately. If the initialization fails, an error is returned. Otherwise, the error is nil.
Scan capture requires access to the device's camera. To avoid runtime errors, add the NSCameraUsageDescription key to your application's Info.plist file. This key allows you to provide a user-facing message explaining why your app needs camera access, for example:
Last updated
Was this helpful?