Introduction
With version 8.0.0 of the Scanbot SDK, we went through our APIs and made several improvements to make them
more consistent and easier to use. The SDK now throws errors instead of returning nil or false in many places.
This also affects how you handle results from various operations in the SDK.
The thrown error is a Swift standard Error protocol. But the underlying error is of type SBSDKError, which contains an error
code and a descriptive message.
To access SDK-specific properties, you need to cast the error to type SBSDKError.
Currently these are the possible error codes:
/// An unknown or unexpected error occurred.
/// - Parameter String: A description of the error that occurred.
case unknownError(String)
/// The SDK license is invalid or license requirements are not satisfied.
/// - Parameter String: Details about the license validation failure.
case invalidLicense(String)
/// A null pointer was encountered where a valid reference was expected.
/// - Parameter String: Description of where the null pointer was encountered.
case nullPointer(String)
/// An invalid argument was passed to an SDK function or method.
/// - Parameter String: Details about which argument was invalid and why.
case invalidArgument(String)
/// An invalid image reference was provided or the image data is corrupted.
/// - Parameter String: Information about the invalid image reference.
case invalidImageRef(String)
/// A required SDK component is unavailable or not properly initialized.
/// - Parameter String: Details about which component is unavailable.
case componentUnavailable(String)
/// The SDK is in an illegal or inconsistent state for the requested operation.
/// - Parameter String: Description of the illegal state condition.
case illegalState(String)
/// An input/output error occurred during file or data operations.
/// - Parameter String: Details about the I/O operation that failed.
case ioError(String)
/// The provided data is invalid, corrupted, or in an unexpected format.
/// - Parameter String: Information about the invalid data encountered.
case invalidData(String)
/// The operation was canceled before completion or by user.
/// - Parameter String: Details about which operation was canceled.
case operationCanceled(String)
/// The system ran out of memory during the operation.
/// - Parameter String: Context about when the out-of-memory condition occurred.
case outOfMemory(String)
/// The operation timed out before completion.
/// - Parameter String: Information about the timeout condition and duration.
case timeout(String)
Handling Error
loading...
Additionally, SBSDKError has a property called isCanceled to check if the error represents a canceled operation.
E.g., if the user taps on the cancel button while using any of the RTU-UI v2 components, the completion handler will be called with an
error where isCanceled is true.
loading...
Handling result in Non-UI components
All scanner and generator classes now have methods that throw errors along with their initializers.
Using do-catch
In the example below, we create an instance of the scanner, then run the scanner on an image, and handle any potential errors using a do-catch block.
loading...
Using try?
While you can do the same using try?, it is not recommended as you will lose the error information.
loading...
Handling result in RTU-UI components
When using RTU-UI v2 components the completion handlers now include an error parameter that you can use to check for errors.
If an error is passed, the result parameter will always be nil and vice versa.
loading...
Handling results in Classic components
Classic components still use delegate methods to return results. A non-optional delegate method didFailScanning, has been added to all
classic scanner delegate protocols. This delegate method allows you to handle errors that occur during scanning.
The delegate method didFailScanning is a required method that should be implemented. It will be called whenever an error
occurs during the scanning process.
loading...
Want to scan longer than one minute?
Generate a free trial license to test the Scanbot SDK thoroughly.
Get free trial license