Objective-C Requires Chilkat v11.7.0+
Objective-C
QR Code Error Correction Levels
See more QR Code Examples
Demonstrates the four QR error-correction levels. L, M, Q and H allow a reader to recover the data when about 7%, 15%, 25% and 30% of the symbol is damaged or covered. More error correction leaves less room for data, so the same text needs a larger symbol at a higher level. The default is M. The example also shows boostErrorCorrection, which raises the level for free when the chosen version has room to spare.Chilkat Objective-C Downloads
#import <CkoFormats.h>
#import <CkoJsonObject.h>
#import <CkoJsonArray.h>
BOOL success = NO;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkoFormats *fmt = [[CkoFormats alloc] init];
CkoJsonObject *json = [[CkoJsonObject alloc] init];
CkoJsonObject *jsonOut = [[CkoJsonObject alloc] init];
[json UpdateString: @"payload.text" value: @"https://www.chilkatsoft.com/barcode_overview.asp"];
// Encode the same text at each level.
CkoJsonArray *levels = [[CkoJsonArray alloc] init];
[levels Load: @"[\"L\",\"M\",\"Q\",\"H\"]"];
int i;
for (i = 0; i <= 3; i++) {
[json UpdateString: @"encoding.qr.errorCorrection" value: [levels StringAt: [NSNumber numberWithInt: i]]];
success = [fmt QrCode: @"generate" jsonIn: json jsonOut: jsonOut];
if (success == NO) {
NSLog(@"%@",fmt.LastErrorText);
return;
}
NSLog(@"%@%@%@%d%@%d%@",@"level ",[levels StringAt: [NSNumber numberWithInt: i]],@": version ",[[jsonOut IntOf: @"symbols[0].selectedEncoding.version"] intValue]
,@", ",[[jsonOut IntOf: @"symbols[0].dimensions.modulesWide"] intValue],@" modules wide");
}
// The four symbols. They hold the same text, and the higher the level, the larger the symbol:
//
// A symbol often has room left over. boostErrorCorrection uses it: the level is raised
// as far as the same version allows, so the symbol is no larger but is more robust.
CkoJsonObject *json2 = [[CkoJsonObject alloc] init];
[json2 UpdateString: @"payload.text" value: @"https://chilkatsoft.com"];
[json2 UpdateString: @"encoding.qr.errorCorrection" value: @"L"];
success = [fmt QrCode: @"generate" jsonIn: json2 jsonOut: jsonOut];
if (success == NO) {
NSLog(@"%@",fmt.LastErrorText);
return;
}
NSLog(@"%@%d%@%@",@"level L requested: version ",[[jsonOut IntOf: @"symbols[0].selectedEncoding.version"] intValue],@", level ",[jsonOut StringOf: @"symbols[0].selectedEncoding.errorCorrection"]);
[json2 UpdateBool: @"encoding.qr.boostErrorCorrection" value: YES];
success = [fmt QrCode: @"generate" jsonIn: json2 jsonOut: jsonOut];
if (success == NO) {
NSLog(@"%@",fmt.LastErrorText);
return;
}
NSLog(@"%@%d%@%@",@"level L with boost: version ",[[jsonOut IntOf: @"symbols[0].selectedEncoding.version"] intValue],@", level ",[jsonOut StringOf: @"symbols[0].selectedEncoding.errorCorrection"]);
// Level L, and level M reached by the boost. The two symbols are the same size:
//
// Sample output:
// level L: version 3, 29 modules wide
// level M: version 4, 33 modules wide
// level Q: version 5, 37 modules wide
// level H: version 6, 41 modules wide
// level L requested: version 2, level L
// level L with boost: version 2, level M