Deprecation warning

Please note that this is outdated documentation for an older release of the Scandit Barcode Scanner SDK.

We are deprecating the 5.x API on all platforms (except Linux). Release 5.19 in April 2021 will be our final. Applications running 5.x will continue to work, and we will continue to release critical bug fixes and security patches only, for one year. We encourage you to migrate to 6.x and take advantage of our latest / advanced features and improved performance.

You'll find the updated documentation at: Data Capture SDK Documentation for Android

Documentation for iOS

Usage Sample

The following code shows typical usage of the parser library.

#import <ScanditParser/ScanditParser.h>

...

NSError *err;
// Replace SBSDataFormatHIBC with the data format of your choice.
// picker: SBSBarcodePicker object from Scandit SDK
SBSParser *parser = [picker parserForFormat:SBSParserDataFormatHIBC error:&err];
if (!parser) {
    // Something went wrong. Look at err for more info.
}

SBSParserResult *result = [parser parseString:@"+A99912345/$$52001510X33" error:&err];
if (!result) {
    // Something went wrong. Look at err for more info.
}

// We can either access the data from the raw JSON string...
NSLog(@"%@", result.jsonString);

// ... or from the fields dictionary...
NSDictionary<NSString*, SBSField*> *fieldsDictionary = result.fieldsDict;
for (NSString *key in fieldsDictionary.allKeys) {
    SBSField *field = [fieldsDictionary objectForKey:key];
    NSLog(@"%@ name: %@", key, field.name);
    NSLog(@"%@ raw: %@", key, field.rawString);
    NSLog(@"%@ parsed: %@", key, field.parsed);
}

// ... or from the fields array
for (SBSField* field in result.fieldsArray) {
    NSLog(@"%@ raw: %@", field.name, field.rawString);
    NSLog(@"%@ parsed: %@", field.name, field.parsed);
}

Some data formats allow for special parsing options which modify the behaviour of the parser. These can be set in the following way:

NSError *err;
NSDictionary *opts = @{
    @"outputHumanReadableString" : @YES
};
[parser setOptions:opts error:&err];

iOS API

class SBSParser

Defines the interface for a data string parser. Parsers are capable of parsing one particular data format, which is passed to them during construction.

parseString:(NSString *)string error:(NSError **)outError;

Parses the data string and returns the contained fields in the result object. In case the result could not be parsed, the error message is accessible as part of the outError parameter.

Returns

The result object. Before accessing the fields of the result, you must ensure that the string was correctly parsed, that is, outError has not been set.

Parameters
  • string – The string to parse. Must not be nil.

  • outError – Upon failure will be set to an instance of NSError containing details on why the data could not be parsed. Can be nil.

Return type

SBSParserResult*

parseRawData:(NSString *)rawData error:(NSError **)outError;

Parses the raw data of the code and returns the contained fields in the result object. In case the result could not be parsed, the error message is accessible as part of the outError parameter.

Returns

The result object. Before accessing the fields of the result, you must ensure that the string was correctly parsed, that is, outError has not been set.

Parameters
  • rawData – The raw data of the string to parse. Must not be nil.

  • outError – Upon failure will be set to an instance of NSError containing details on why the data could not be parsed. Can be nil.

Return type

SBSParserResult*

setOptions:(NSDictionary *)opts error:(NSError **)outError;

Apply the option map to the parser, allowing the user to fine-tune the behaviour of the parser. Available options depend on the data format and are specified in the respective documentation. If the case that the options object is invalid and the operation fails, the error message is accessible as part of the outError parameter.

Parameters
  • opts – The options dictionary. Must not be nil.

  • outError – Upon failure will be set to an instance of NSError containing details on why the operation failed. Can be nil.

Return type

void

class SBSParserResult

The SBSParserResult holds the result of a successfully parsed data string. The result is a collection of fields that can either be accessed as an sequential array (fieldsArray), or a dictionary (fieldsDict) which maps field name onto values.

json

The JSON string of the result content.

Type

NSString*

fieldsDict

Dictionary of SBSParserField objects with key being the field name.

Type

NSDictionary<NSString*, SBSParserField*>*

fieldsArray

Array of SBSParserField objects with key being the field name. Use this accessor if the order of the fields in the string matter, if you are only interested in a particular field, using the SBSParserField.fieldsDict is simpler.

Type

NSArray<SBSParserField*>*

class SBSParserField

A particular field of the parsed result.

name

The name of the field.

Type

NSString*

This attribute corresponds to the JSON “name” field.

rawString

Raw substring of the original code containing the field data. For fields that are inferred and do not have a direct correspondence to a particular part of the string, the string is set to an empty string. An example of such a field is the Metadata field field of HIBC codes.

Type

NSString*

This attribute corresponds to the JSON “rawString” field.

parsed

The parsed representation of the data contained in this field. If no parsed representation is available for the field, this property is nil. Use SBSParserField.rawString to retrieve the data for these fields.

Type

id. Depending on the field, this may be an instance of NSNumber, NSDictionary, NSArray, or NSString.

This attribute corresponds to the JSON “parsed” field.