SBSDKMachineReadableCodeManager

@interface SBSDKMachineReadableCodeManager : NSObject

Helper class to parse and transform SBSDKMachineReadableCodeMetadata into specific SBSDKMachineReadableCode subclass instances. To transform a metadata object into a machine readable code object a matching parser is needed.

Parsers must conform to the SBSDKMachineReadableCodeParsing protocol and must be registered using the registerParser method.

Typically a parsers parseMetadata method takes an SBSDKMachineReadableCodeMetadata object, parses its stringValue and eventually returns an instance of a SBSDKMachineReadableCode subclass. If the parsing fails or the stringValue does not match the parsers pattern, the parser should return nil.

ScanbotSDK comes with some basic default parsers and can be extended with custom machine readable codes and their matching parsers.

  • Declaration

    Objective-C

    + (instancetype _Nonnull)defaultManager;

    Swift

    class func `default`() -> Self

    Return Value

    The default instance with pre-registered ScanbotSDK parsers and machine readable codes. If you don’t want to invoke the default parsers, create your own instance using the init method and register your custom parsers there.

  • Registers your custom machine readable code parser. Make sure you register each custom parser once only.

    Declaration

    Objective-C

    - (void)registerParser:(nonnull id<SBSDKMachineReadableCodeParsing>)parser;

    Swift

    func registerParser(_ parser: SBSDKMachineReadableCodeParsing)

    Parameters

    parser

    Your custom SBSDKMachineReadableCode parser.

  • Traverses through all registered parsers in reverse order and tries to transform the metadata object into a machine readable code object. Returns the first successfully parsed machine readable code.

    Declaration

    Objective-C

    - (nullable SBSDKMachineReadableCode *)parseCodeFromMetadata:
        (nonnull SBSDKMachineReadableCodeMetadata *)metadata;

    Swift

    func parseCode(from metadata: SBSDKMachineReadableCodeMetadata) -> SBSDKMachineReadableCode?

    Parameters

    metadata

    The SBSDKMachineReadableCodeMetadata to transform into SBSDKMachineReadableCode.

    Return Value

    First successfully parsed machine readable code object, or nil, if no parser was matching.

  • Traverses through all registered parsers in reverse order and tries to transform the metadata object into a machine readable code object. Returns all successfully parsed machine readable codes.

    Declaration

    Objective-C

    - (nonnull NSArray<SBSDKMachineReadableCode *> *)parseAllCodesFromMetadata:
        (nonnull SBSDKMachineReadableCodeMetadata *)metadata;

    Swift

    func parseAllCodes(from metadata: SBSDKMachineReadableCodeMetadata) -> [SBSDKMachineReadableCode]

    Parameters

    metadata

    The SBSDKMachineReadableCodeMetadata to transform into SBSDKMachineReadableCode.

    Return Value

    An array of successfully parsed machine readable code objects. Returns an empty array if no parser was matching.