Green Book

Declaration

func scanGreenBook(
    on viewController: UIViewController, 
    doneLaunching: SybrinIdentity.doneLaunchingType? = nil, 
    success: SybrinIdentity.greenBookSuccessCallbackType? = nil, 
    failure: SybrinIdentity.failureCallbackType? = nil, 
    cancel: SybrinIdentity.cancelCallbackType? = nil
)

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

Handling the doneLaunching , success , failureor cancel callbacks are optional but recommended.

Calling the function

Parameters

Type

Description

UIViewController

The controller you would like to present on.

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 green book.

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

This is not required, but is recommended if you would like to access the country model's specific properties.

The result will be of type SouthAfricaGreenBookModel, but is returned in its parent form GreenBookModel. To access all the data specific to SouthAfricaGreenBookModel you will need to cast the GreenBookModel to that type.

Example:

success: { (model) in
    if let southAfricaGreenBook = model as? SouthAfricaGreenBookModel {
        print("This is a south african green book model!")
    }
}

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("Scan green book 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("Scan green book canceled")
}

Full Example

SybrinIdentity.shared.scanGreenBook(on: self) 
{ (didLaunch, message) in
    if didLaunch {
        print("Launched successfully!")
    } else if let message = message {
        print("Failed to launch because \(message)")
    }
} success: { (model) in
    if let model = model as? SouthAfricaGreenBookModel {
        print("Scan green book success: \(model.identityNumber ?? "")")
    }
} failure: { (message) in
    print("Scan green book failed because \(message)")
} cancel: {
    print("Scan green book canceled")
}

Last updated