Objective-C Requires Chilkat v11.7.0+
Objective-C
Split Data across Several QR Codes (Structured Append)
See more QR Code Examples
Demonstrates structured append, the QR feature for data too large for one symbol of the size wanted. The data is divided over up to 16 symbols, and each carries its position, the total, and a parity byte that ties the set together. With encoding.structuredAppend.enabled, QrCode uses as few symbols as it can. output.pathTemplate writes one file per symbol, with {index} replaced by 1, 2, 3 and so on. The reader must support structured append to put the parts back together. Many phone camera apps do not, and show each part separately.Chilkat Objective-C Downloads
#import <CkoStringBuilder.h>
#import <CkoJsonObject.h>
#import <CkoFormats.h>
BOOL success = NO;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// Some text that is too long for one symbol of the size allowed below.
CkoStringBuilder *sbText = [[CkoStringBuilder alloc] init];
int i;
for (i = 1; i <= 20; i++) {
[sbText Append: @"Line "];
[sbText AppendInt: [NSNumber numberWithInt: i]];
[sbText AppendLine: @" of a message that is too long for one small QR code." crlf: YES];
}
CkoJsonObject *json = [[CkoJsonObject alloc] init];
[json UpdateSb: @"payload.text" sb: sbText];
// Keep each symbol small (version 10 is 57 modules wide) and allow a set of symbols.
[json UpdateInt: @"encoding.qr.maxVersion" value: [NSNumber numberWithInt: 10]];
[json UpdateBool: @"encoding.structuredAppend.enabled" value: YES];
// One file for each symbol: qr_part_1.png, qr_part_2.png, ...
[json UpdateString: @"output.pathTemplate" value: @"qa_output/qr_part_{index}.png"];
[json UpdateBool: @"output.overwrite" value: YES];
[json UpdateString: @"output.return" value: @"none"];
CkoFormats *fmt = [[CkoFormats alloc] init];
CkoJsonObject *jsonOut = [[CkoJsonObject alloc] init];
success = [fmt QrCode: @"generate" jsonIn: json jsonOut: jsonOut];
if (success == NO) {
NSLog(@"%@",fmt.LastErrorText);
return;
}
NSLog(@"%@%d",@"text length: ",[sbText.Length intValue]);
int numSymbols = [[jsonOut SizeOfArray: @"symbols"] intValue];
NSLog(@"%@%d",@"symbols: ",numSymbols);
for (i = 0; i <= numSymbols - 1; i++) {
jsonOut.I = [NSNumber numberWithInt: i];
// structuredAppend.index counts from 0.
NSLog(@"%@%@%d%@%d%@%d%@%d%@",[jsonOut StringOf: @"outputs[i].path"],@": symbol ",([[jsonOut IntOf: @"symbols[i].structuredAppend.index"] intValue] + 1),@" of "
,[[jsonOut IntOf: @"symbols[i].structuredAppend.total"] intValue],@", version ",[[jsonOut IntOf: @"symbols[i].selectedEncoding.version"] intValue],@", ",[[jsonOut IntOf: @"symbols[i].payloadBytes"] intValue]
,@" bytes");
}
// Every symbol of a set carries the same parity byte, which is how a reader knows they belong together.
NSLog(@"%@%d",@"parity: ",[[jsonOut IntOf: @"symbols[0].structuredAppend.parity"] intValue]);
// The six symbols:
//
// Sample output:
// text length: 1231
// symbols: 6
// qa_output/qr_part_1.png: symbol 1 of 6, version 10, 206 bytes
// qa_output/qr_part_2.png: symbol 2 of 6, version 10, 205 bytes
// qa_output/qr_part_3.png: symbol 3 of 6, version 10, 205 bytes
// qa_output/qr_part_4.png: symbol 4 of 6, version 10, 205 bytes
// qa_output/qr_part_5.png: symbol 5 of 6, version 10, 205 bytes
// qa_output/qr_part_6.png: symbol 6 of 6, version 10, 205 bytes
// parity: 50