SDK

Adding the SDK to your project

To add our SDK to your own application, you should add it to the build process of your application. Currently we support doing this using CocoaPods or Carthage.

CocoaPods: Adding the SDK to your Podfile

To add the repository to your project, open the Podfile, if it does not exists, first run pod init in the root of your project with Xcode closed.
Edit the target part of your application in the Podfile, so that it contains the following:

                    
pod 'Klippa-Utility-Meter-Scanner', podspec: 'https://custom-ocr.klippa.com/sdk/ios/specrepo/ExampleUsername/ExamplePassword/KlippaUtilityMeterScanner/latest.podspec'
                    
                

The full Podfile might look like this now:

                    
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'

target 'TestScanner' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!

  # Pods for TestScanner
  pod 'Klippa-Utility-Meter-Scanner', podspec: 'https://custom-ocr.klippa.com/sdk/ios/specrepo/ExampleUsername/ExamplePassword/KlippaUtilityMeterScanner/latest.podspec'

end
                    
                

When you run pod install now, it should download our library as dependency, and with that all dependencies of our library.
Note: this code always uses the latest version, you can also use a specific version to make sure the SDK won't update without your knowledge.

Carthage: Adding the SDK to your Cartfile

To add the repository to your project, open the Cartfile, if it does not exists, create a Cartfile alongside your .xcodeproj or .xcworkspace.
Add the following to your Cartfile:

                    
binary "https://custom-ocr.klippa.com/sdk/ios/carthage/ExampleUsername/ExamplePassword/KlippaUtilityMeterScanner.json"
                    
                

When you run carthage update now, it should download our library as dependency, and with that all dependencies of our library.
Note: this code always uses the latest version, you can also use a specific version to make sure the SDK won't update without your knowledge.

Starting the Utility Meter Scanner

To start the scanner, import our library in your AppDelegate:

                    
// Add to the top of your file
import KlippaUtilityMeterScanner
                    
                

Then init the scanner options inside your launch method:

                    
// Add license
UtilityMeterScannerBuilder.setup.license = "replace-with-received-license"

                    
                

In the controller that you want to launch the scanner, implement the UtilityMeterScannerControllerDelegate:

                    
// Add to the top of your file
import KlippaUtilityMeterScanner

// Your class definition should look like this.
final class ExampleScannerViewController: UIViewController, UtilityMeterScannerControllerDelegate {

    // ... Rest of your controller code.

    func startScanner() {
        let scannerViewController = UtilityMeterScannerController()
        scannerViewController.utilityMeterScannerDelegate = self
        scannerViewController.modalPresentationStyle = .fullScreen
        present(scannerViewController, animated: false)
    }

    func utilityMeterScannerController(_ scanner: UtilityMeterScannerController, didFailWithError error: Error) {
        switch error {
        case let licenseError as LicenseError:
            print("Got licensing error from SDK: \(licenseError.localizedDescription)")
        default:
            print(error)
        }
    }

    func utilityMeterScannerController(_ scanner: UtilityMeterScannerController, didFinishScanningWithResult result: UtilityMeterScannerResult) {
        // Handle scan results here.
        print("didFinishScanningWithResults")
        print("multipleDocumentsModeEnabled \(result.multipleDocumentsModeEnabled)")
        print("Scanned \(result.meters.count) items")
    }

    func utilityMeterScannerControllerDidCancel(_ scanner: UtilityMeterScannerController) {
        scanner.dismiss(animated: true, completion: nil)
    }

    // ... Rest of your controller code.
}
                     
                

In the place where you want to start the scanner, for example after a button click, call the startScanner method:

                    
startScanner()
                    
                

Customizing the utility meter scanner

The SDK has a few customizing settings, the following methods are available:

                    
// Set object detection sensitivity
UtilityMeterScannerBuilder.setup.extractionModel.threshold = 0.5

// Which values can be edited during review screen.
UtilityMeterScannerBuilder.setup.extractionModel.canEditKeys = ["QR-Code", "Barcode", "Value"]

// Whether to show the icon to enable "multi-document-mode"
UtilityMeterScannerBuilder.setup.set(allowMultipleDocumentsMode: true)

// Whether the "multi-document-mode" should be enabled by default.
UtilityMeterScannerBuilder.setup.set(isMultipleDocumentsModeEnabled: true)

// Ability to disable/hide the shutter button (only works when a model is supplied as well).
UtilityMeterScannerBuilder.setup.set(allowShutterButton: true, hideShutterButton: false)

// Whether the crop mode (auto edge detection) should be enabled by default.
UtilityMeterScannerBuilder.setup.set(cropEnabled: true)

// Define the max resolution of the output file. It’s possible to set only one of these values. We will make sure the picture fits in the given resolution. We will also keep the aspect ratio of the image. Default is max resolution of camera.
UtilityMeterScannerBuilder.setup.imageMaxWidth = 1920
UtilityMeterScannerBuilder.setup.imageMaxHeight = 1080

// Set the output quality (between 0-100) of the jpg encoder. Default is 100.
UtilityMeterScannerBuilder.setup.imageMaxQuality = 95

// The warning message when someone should move closer to a document, should be a string.
UtilityMeterScannerBuilder.setup.moveCloserMessage = "Move closer to the document"

// The warning message when the camera preview has too much motion to be able to automatically take a photo.
UtilityMeterScannerBuilder.setup.imageMovingMessage = "Too much movement"

// The warning message when the camera result is too bright.
UtilityMeterScannerBuilder.setup.imageTooBrightMessage = "The image is too bright"

// The warning message when the camera result is too dark.
UtilityMeterScannerBuilder.setup.imageTooDarkMessage = "The image is too dark"

// Ability to limit amount of pictures that can be taken and set a message once the limit has been reached.
UtilityMeterScannerBuilder.setup.set(imageLimitReachedMessage: "Limit reached", imageLimit: 10)

// The primary color of the interface, should be a UIColor.
UtilityMeterScannerBuilder.setup.primaryColor = UIColor(red: 0.153, green: 0.733, blue: 0.373, alpha: 1.00)

// The accent color of the interface, should be a UIColor.
UtilityMeterScannerBuilder.setup.accentColor = UIColor(red: 0.153, green: 0.733, blue: 0.373, alpha: 1.00)

// The overlay color (when using document detection), should be a UIColor.
UtilityMeterScannerBuilder.setup.overlayColor = UIColor(red: 0.17, green: 0.77, blue: 0.41, alpha: 1.00)

// The color of the background of the warning message, should be a UIColor.
UtilityMeterScannerBuilder.setup.warningBackgroundColor = .red

// The color of the text of the warning message, should be a UIColor.
UtilityMeterScannerBuilder.setup.warningTextColor = .white

// The color of the menu icons when they are enabled, should be a UIColor.
UtilityMeterScannerBuilder.setup.iconEnabledColor = .white

// The color of the menu icons when they are disabled, should be a UIColor.
UtilityMeterScannerBuilder.setup.iconDisabledColor = .gray

// The color of the menu icons of the screen where you can review/edit the images, should be a UIColor.
UtilityMeterScannerBuilder.setup.reviewIconColor = .white

// The amount of opacity for the overlay, should be a float.
UtilityMeterScannerBuilder.setup.overlayColorAlpha = 0.75

// The amount of seconds the preview should be visible for, should be a float.
UtilityMeterScannerBuilder.setup.previewDuration = 1.0

// Whether the camera has a view finder overlay (a helper grid so the user knows where the document should be), should be a Boolean.
UtilityMeterScannerBuilder.setup.isViewFinderEnabled = true

// If you would like to use a custom model for object detection. Model + labels file should be packaged in your bundle.
UtilityMeterScannerBuilder.setup.set(modelName: "model", modelLabelsName: "labels")

// If you would like to enable automatic capturing of images.
UtilityMeterScannerBuilder.setup.isTimerEnabled = true
UtilityMeterScannerBuilder.setup.timerDuration = 0.5

// To add extra horizontal and / or vertical padding to the cropped image.
UtilityMeterScannerBuilder.setup.set(cropPadding: CGSize(width: 100, height: 100))

// After capture, show a checkmark preview with this success message, instead of a preview of the image.
UtilityMeterScannerBuilder.setup.set(successMessage: "Success!", successPreviewDuration: 0.3)

// Whether the camera automatically saves the images to the camera roll. Default true. (iOS version 0.4.2 and up only)
UtilityMeterScannerBuilder.setup.storeImagesToCameraRoll = true

// The threshold sensitive the motion detection is. (lower value is higher sensitivity, default 200).
UtilityMeterScannerBuilder.setup.imageMovingSensitivity = 200
                    
                

Requesting Authorization for Media Capture and Image Saving

Include the NSCameraUsageDescription key in your app’s Info.plist file.

                    
                        <key>NSCameraUsageDescription</key>
                        <string>In order to scan documents, we need access to your camera.</string>
                    
                

Saving scans to the user’s photo library, include the NSPhotoLibraryAddUsageDescription key in your app’s Info.plist file.

                    
                        <key>NSPhotoLibraryAddUsageDescription</key>
                        <string>In order to save scans we need access to your photos.</string>
                    
                

Versions

The following versions are available:

Versions Table
Version Podspec include URL Cartfile dependency Binary download
0.0.2 https://custom-ocr.klippa.com/sdk/ios/specrepo/ExampleUsername/ExamplePassword/KlippaUtilityMeterScanner/0.0.2.podspec binary "https://custom-ocr.klippa.com/sdk/ios/carthage/ExampleUsername/ExamplePassword/KlippaUtilityMeterScanner.json" == 0.0.2 Fat framework (.xcarchive) | XCFramework
0.0.1 https://custom-ocr.klippa.com/sdk/ios/specrepo/ExampleUsername/ExamplePassword/KlippaUtilityMeterScanner/0.0.1.podspec binary "https://custom-ocr.klippa.com/sdk/ios/carthage/ExampleUsername/ExamplePassword/KlippaUtilityMeterScanner.json" == 0.0.1 Fat framework (.xcarchive) | XCFramework

Changelog

0.0.2

Changed

  • Renamed ImageScannerController to UtilityMeterScannerController.
  • Renamed ImageScannerControllerDelegate to UtilityMeterScannerControllerDelegate.
  • Renamed KlippaUtilityMeterScanner to UtilityMeterScannerBuilder.
  • Minimum iOS deployment target to 13.0.

0.0.1

  • First release of Utility Meter Scanner SDK