Address Extraction

Declaration

With Camera

func captureWithCamera(
    on viewController: UIViewController, 
    for document: Document, 
    doneLaunching: SybrinDocumentScanner.doneLaunchingType? = nil, 
    success: SybrinDocumentScanner.successCallbackType? = nil, 
    failure: SybrinDocumentScanner.failureCallbackType? = nil, 
    cancel: SybrinDocumentScannertity.cancelCallbackType? = nil
)
func captureWithGallery(
    on viewController: UIViewController, 
    for document: DocumentType, 
    doneLaunching: SybrinDocumentScanner.doneLaunchingType? = nil, 
    success: SybrinDocumentScanner.successCallbackType? = nil, 
    failure: SybrinDocumentScanner.failureCallbackType? = nil, 
    cancel: SybrinDocumentScanner.cancelCallbackType? = nil
)

To view all the type aliases, go to the SybrinDocumentScanner class

Calling the function

Parameters

Type

Description

UIViewController

The controller you would like to present on.

The document type you would like to scan for.

Handling callback responses

doneLaunching

The doneLaunching callback will be executed after the view controller has successfully launched, or if the view controller failed to launch.

Parameters:

Type

Description

Bool

true if the view controller presented successfully; otherwise, false.

String?

If an error occurs, a message describing the error; otherwise, nil.

Example:

doneLaunching: { (didLaunch, message) in
    if didLaunch {
        print("Launched successfully!")
    } else if let message = message {
        print("Failed to launch because \(message)")
    }
}

success

The success callback will be executed after scanning has finished and the view controller has been dismissed.

Parameters:

Type

Description

An object containing the results of the scanned document.

As explained in Features, the success callback will always return the specific model but in its parent class form (DataModel). However, this can be casted to the specific model to access that model's specific properties.

Let's say that you provide the captureWithCamera function with the .AddressExtraction parameter. The result will be of type AddressDocumentDataModel, but is returned in its parent form DataModel. To access all the data specific to AddressDocumentDataModel you will need to cast the DataModel to that type.

Example:

success: { (model) in
    if let addressData = model as? AddressDocumentDataModel {
        print("This is an address document model! \(addressData.addresses)")
    }
}

failure

The failure callback will be executed after scanning has failed and the view controller has been dismissed.

Parameters:

Type

Description

String?

A message describing the error.

If you would like to report a bug, contact us!

Example:

failure: { (message) in
    print("capture failed because \(message)")
}

cancel

The cancel callback will be executed after the user has dismissed the view controller and before scanning could finish.

Parameters:

None

Example:

cancel: {
    print("capture canceled")
}

Full Example

With Camera

SybrinDocumentScanner.shared.captureWithCamera(on: self, for: .AddressExtraction) 
{ (didLaunch, message) in
    if didLaunch {
        print("Launched successfully!")
    } else if let message = message {
        print("Failed to launch because \(message)")
    }
} success: { (model) in
    if let addressData = model as? AddressDocumentDataModel {
        print("This is an address document model! \(addressData.addresses)")
    }
} failure: { (message) in
    print("Scan document failed because \(message)")
} cancel: {
    print("Scan document canceled")
}
SybrinDocumentScanner.shared.captureWithGallery(on: self, for: .AddressExtraction) 
{ (didLaunch, message) in
    if didLaunch {
        print("Launched successfully!")
    } else if let message = message {
        print("Failed to launch because \(message)")
    }
} success: { (model) in
    if let addressData = model as? AddressDocumentDataModel {
        print("This is an address document model! \(addressData.addresses)")
    }
} failure: { (message) in
    print("Scan document failed because \(message)")
} cancel: {
    print("Scan document canceled")
}

Last updated