SDK Initialization

Initializing PensaSdk

Developing with SwiftUI framework

The Pensa SDK's functionality is encapsulated within a shared object, allowing developers to interact with its API.

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()
        }
    }
}

Developing with UIKit

Import the PensaSdk framework in your app's AppDelegate class and call initPensa() with PensaConfiguration.Builder() method inside the didFinishLaunchingWithOptions method.

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()

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?