-
Notifications
You must be signed in to change notification settings - Fork 89
Using ZXing recognizer
ZXing recognizer is responsible for scanning all existing barcode formats except PDF417. PDF417 is scanned with PDF417 recognizer. Code 39 and Code 128 barcodes are scanned with BarDecoder Recognizer. For all other types, use ZXing.
Supported barcode types in ZXingRecognizer:
- Aztec (alpha quality)
- Code 39
- Code 128
- Data Matrix (alpha quality)
- EAN 13
- EAN 8
- ITF
- QR code
- UPCA
- UPCE
If you completed Obtaining scanning results guide, you learned that in order to use a specific recognizer, you need to specify Recognizer Settings object in the initialization stage, and collect Recognizer Result object in the success callback.
To use ZXing Recognizer, you need to use PZXingRecognizerSettings
object for initialization, and PPZXingRecognizerResult
for collecting results.
Back to "Getting started" guide.
Below is the sample source code which initializes the scanning for PDF417 barcodes, and specifies default values for all available parameteres.
// To specify we want to perform ZXing recognition, initialize the ZXing recognizer settings
PPZXingRecognizerSettings *zxingRecognizerSettings = [[PPZXingRecognizerSettings alloc] init];
// Set this to YES to scan Aztec 2D barcodes
zxingRecognizerSettings.scanAztec = NO;
// Set this to YES to scan Code 128 1D barcodes
zxingRecognizerSettings.scanCode128 = NO;
// Set this to YES to scan Code 39 1D barcodes
zxingRecognizerSettings.scanCode39 = NO;
// Set this to YES to scan DataMatrix 2D barcodes
zxingRecognizerSettings.scanDataMatrix = NO;
// Set this to YES to scan EAN 13 barcodes
zxingRecognizerSettings.scanEAN13 = YES;
// Set this to YES to scan EAN8 barcodes
zxingRecognizerSettings.scanEAN8 = NO;
//Set this to YES to scan ITF barcodes
zxingRecognizerSettings.scanITF = NO;
// Set this to YES to scan QR barcodes
zxingRecognizerSettings.scanQR = YES;
// Set this to YES to scan UPCA barcodes
zxingRecognizerSettings.scanUPCA = NO;
// Set this to YES to scan UPCE barcodes
zxingRecognizerSettings.scanUPCE = NO;
// Set this to YES to allow scanning barcodes with inverted intensities
// (i.e. white barcodes on black background)
// NOTE: this options doubles the frame processing time
zxingRecognizerSettings.scanInverse = NO;
// Add ZXingDecoderRecognizer setting to a list of used recognizer settings
[settings.scanSettings addRecognizerSettings:zxingRecognizerSettings];
Below is the sample source code which collects results of PDF417 barcode scanning.
- (void)scanningViewController:(UIViewController<PPScanningViewController> *)scanningViewController
didOutputResults:(NSArray<PPRecognizerResult *> *)results {
// Here you process scanning results. Scanning results are given in the array of PPRecognizerResult objects.
// first, pause scanning until we process all the results
[scanningViewController pauseScanning];
// Collect data from the result
for (PPRecognizerResult* result in results) {
// Check if result is ZXing result
if ([result isKindOfClass:[PPZXingRecognizerResult class]]) {
// Cast result to PPZXingRecognizerResult
PPZXingRecognizerResult *zxingResult = (PPZXingRecognizerResult *)result;
// check barcode type
switch (zxingResult.barcodeType) {
// Aztec
case PPZXingBarcodeTypeAztec:
NSLog(@"Barcode type is Aztec:");
break;
// Aztec
case PPZXingBarcodeTypeCode128:
NSLog(@"Barcode type is Code 128:");
break;
// Code 39
case PPZXingBarcodeTypeCode39:
NSLog(@"Barcode type is Code 39");
break;
// Data Matrix
case PPZXingBarcodeTypeDataMatrix:
NSLog(@"Barcode type is Data Matrix:");
break;
// EAN 13
case PPZXingBarcodeTypeEAN13:
NSLog(@"Barcode type is EAN 13:");
break;
// EAN 8
case PPZXingBarcodeTypeEAN8:
NSLog(@"Barcode type is EAN 8:");
break;
// ITF
case PPZXingBarcodeTypeITF:
NSLog(@"Barcode type is ITF:");
break;
// QR code
case PPZXingBarcodeTypeQR:
NSLog(@"Barcode type is QR:");
break;
// UPCA
case PPZXingBarcodeTypeUPCA:
NSLog(@"Barcode type is UPCA:");
break;
// UPCE
case PPZXingBarcodeTypeUPCE:
NSLog(@"Barcode type is UPCE:");
break;
}
// If you don't know the exact encoding of the text use stringUsingGuessedEncoding
NSLog(@"%@", [zxingResult stringUsingGuessedEncoding]);
// If you know exactly which encoding is used in the barcode, specify it manually
NSLog(@"%@", [zxingResult stringUsingEncoding:NSUTF8StringEncoding]);
// If the barcode contains raw bytes instead of just text, obtain detailed barcode data
NSLog(@"%@", [zxingResult rawData]);
}
};
// either resume scanning, or dismiss Scanning View controller
// [scanningViewController resumeScanningAndResetState:YES];
[scanningViewController dismissViewControllerAnimated:YES completion:nil];
}
- Getting Started with BlinkID SDK
- Obtaining scanning results
- Using Direct Processing API
- Customizing Camera UI
- Creating customized framework
- Upgrading from older versions
- Troubleshoot