Sample code for 30+ languages & platforms
Objective-C Requires Chilkat v11.7.0+

QR Code with Binary Data

See more QR Code Examples

Demonstrates a QR code that holds arbitrary bytes rather than text. The payload type is binary and the bytes are given as base64 in payload.base64. Any byte value may be used, including zero. Keep in mind that many phone camera apps expect text, so binary payloads are for readers that you control.

Chilkat Objective-C Downloads

Objective-C
#import <CkoBinData.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.

//  The bytes to encode.  Here they come from hex, but they could be loaded from a file with LoadFile.
CkoBinData *bd = [[CkoBinData alloc] init];
success = [bd AppendEncoded: @"000102030405FF00FE4368696C6B6174" encoding: @"hex"];
if (success == NO) {
    NSLog(@"%@",bd.LastErrorText);
    return;
}

CkoJsonObject *json = [[CkoJsonObject alloc] init];
[json UpdateString: @"payload.type" value: @"binary"];
[json UpdateString: @"payload.base64" value: [bd GetEncoded: @"base64"]];
[json UpdateString: @"output.path" value: @"qa_output/qr_binary.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",@"bytes given: ",[bd.NumBytes intValue]);
NSLog(@"%@%d",@"bytes encoded: ",[[jsonOut IntOf: @"symbols[0].payloadBytes"] intValue]);
NSLog(@"%@%@",@"mode: ",[jsonOut StringOf: @"symbols[0].selectedEncoding.mode"]);
NSLog(@"%@%d",@"QR version: ",[[jsonOut IntOf: @"symbols[0].selectedEncoding.version"] intValue]);

//  The image written to qa_output/qr_binary.png:

//  image

//  Sample output:

//  bytes given: 16
//  bytes encoded: 16
//  mode: byte
//  QR version: 2