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

Create a vCard (Contact) QR Code

See more QR Code Examples

Demonstrates a QR code that adds a contact to a phone when scanned. The text is a vCard, the standard format for contact details: lines between BEGIN:VCARD and END:VCARD, each ending with CRLF. A vCard is fairly long, so the symbol is larger than one holding a web address. Leave out the fields that are not needed to keep it small.

Chilkat Objective-C Downloads

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

//  The second argument of AppendLine is cktrue to end each line with CRLF.
CkoStringBuilder *sbCard = [[CkoStringBuilder alloc] init];
[sbCard AppendLine: @"BEGIN:VCARD" crlf: YES];
[sbCard AppendLine: @"VERSION:3.0" crlf: YES];
[sbCard AppendLine: @"N:Smith;Alex;;;" crlf: YES];
[sbCard AppendLine: @"FN:Alex Smith" crlf: YES];
[sbCard AppendLine: @"ORG:Example Company" crlf: YES];
[sbCard AppendLine: @"TITLE:Sales Manager" crlf: YES];
[sbCard AppendLine: @"TEL;TYPE=CELL:+1-555-0100" crlf: YES];
[sbCard AppendLine: @"EMAIL:alex.smith@example.com" crlf: YES];
[sbCard AppendLine: @"URL:https://www.example.com" crlf: YES];
[sbCard AppendLine: @"END:VCARD" crlf: YES];

CkoJsonObject *json = [[CkoJsonObject alloc] init];
[json UpdateSb: @"payload.text" sb: sbCard];
[json UpdateInt: @"render.moduleSize" value: [NSNumber numberWithInt: 6]];
[json UpdateString: @"output.path" value: @"qa_output/qr_vcard.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",@"vCard length: ",[sbCard.Length intValue]);
NSLog(@"%@%d",@"QR version: ",[[jsonOut IntOf: @"symbols[0].selectedEncoding.version"] intValue]);
NSLog(@"%@%d%@%d",@"modules: ",[[jsonOut IntOf: @"symbols[0].dimensions.modulesWide"] intValue],@" x ",[[jsonOut IntOf: @"symbols[0].dimensions.modulesHigh"] 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_vcard.png:

//  image

//  Sample output:

//  vCard length: 197
//  QR version: 10
//  modules: 57 x 57
//  image: 390 x 390 pixels