Objective-C Requires Chilkat v11.7.0+
Objective-C
Generate a QR Code with the Barcode Method
See more QR Code Examples
Demonstrates the Barcode method, which is the general form of QrCode: the request names the symbology, and everything else is the same. QrCode is Barcode with the symbology already set to qr, and identical requests to the two methods give identical results. A program that will produce more than one kind of barcode can use Barcode for all of them.Chilkat Objective-C Downloads
#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.
CkoJsonObject *json = [[CkoJsonObject alloc] init];
[json UpdateString: @"symbology" value: @"qr"];
[json UpdateString: @"payload.text" value: @"https://www.chilkatsoft.com/"];
[json UpdateString: @"output.path" value: @"qa_output/qr_from_barcode.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 Barcode: @"generate" jsonIn: json jsonOut: jsonOut];
if (success == NO) {
NSLog(@"%@",fmt.LastErrorText);
return;
}
NSLog(@"%@%@",@"symbology: ",[jsonOut StringOf: @"symbols[0].symbology"]);
NSLog(@"%@%d",@"QR version: ",[[jsonOut IntOf: @"symbols[0].selectedEncoding.version"] intValue]);
NSLog(@"%@%d%@%d%@",@"image: ",[[jsonOut IntOf: @"outputs[0].width"] intValue],@" x ",[[jsonOut IntOf: @"outputs[0].height"] intValue],@" pixels");
// The image written to qa_output/qr_from_barcode.png:
//
// Barcode requires the symbology. QrCode does not.
CkoJsonObject *json2 = [[CkoJsonObject alloc] init];
[json2 UpdateString: @"payload.text" value: @"https://www.chilkatsoft.com/"];
success = [fmt Barcode: @"generate" jsonIn: json2 jsonOut: jsonOut];
if (success == NO) {
NSLog(@"%@%@%@%@",@"without a symbology: ",[jsonOut StringOf: @"errors[0].code"],@" at ",[jsonOut StringOf: @"errors[0].path"]);
}
// Sample output:
// symbology: qr
// QR version: 3
// image: 148 x 148 pixels
// without a symbology: missingOption at /symbology