QRCode for vCard

The project is to create QRCode for digital vCard. I've generated QRCode for following contact fields and be able to be read by iPhone camera: Name(N:), Telephone(TEL:), Email(Email:), url(URL:) and Note(NOTE:) But no luck on fields: Company, Address, Social Profile and photo:

textToQRCode = "BEGIN:VCARD\n" + 
"N:\(lastName);\(firstName)\n" +
"TEL:\(phoneNumber)\n" +
"Email:\(email)\n" +
"NOTE:\(notes)\n" +
"END:VCARD" 

Any suggestions? Thanks!

Answered by Claude31 in 735314022

Both QR code work. So I do not see what does not work. Could you show and explain such an example ?

Here is a vcard 4.0 format:

BEGIN:VCARD
VERSION:4.0
N:Gump;Forrest;;Mr.;
FN:Forrest Gump
ORG:Bubba Gump Shrimp Co.
TITLE:Shrimp Man
PHOTO;MEDIATYPE=image/gif:http://www.example.com/dir_photos/my_photo.gif
TEL;TYPE=work,voice;VALUE=uri:tel:+1-111-555-1212
TEL;TYPE=home,voice;VALUE=uri:tel:+1-404-555-1212
ADR;TYPE=WORK;PREF=1;LABEL="100 Waters Edge\nBaytown\n, LA 30314\nUnited States of America":;;100 Waters Edge;Baytown;LA;30314;United States of America
ADR;TYPE=HOME;LABEL="42 Plantation St.\nBaytown\, LA 30314\nUnited States of America":;;42 Plantation St.;Baytown;LA;30314;United States of America
EMAIL:forrestgump@ example.com
REV:20080424T195243Z
x-qq:21588891
END:VCARD

What is it that does not work ?

I am running into rather interesting situation:

  1. If I put in limited information to generate QRCode, it works perfect on reading QRCode. Information like N,ORG,TITLE,ADR (without country;United States of America)
  2. As soon as I add more information like "United States of America", or email address, the QRCode generated will no longer readable.

I checked limitation of QRCode, somewhere mentioned RACode limited to 4,269 alphanumeric characters, not sure that's the reason?!

..

Yes, size may be the reason. And size depends on QRCode type. Which type did you select ?

Is it CIQRCodeGenerator ? which allows for 2285 chars

Yes, CIQRCodeGenerator, which one I should use for more characters?

AFAIK, it depends on what you encode (because that influences the compression rate):

https://en.wikipedia.org/wiki/QR_code

    Numeric only    Max. 7,089 characters (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
    Alphanumeric    Max. 4,296 characters (0–9, A–Z [upper-case only], space, $, %, *, +, -, ., /, :)
    Binary/byte     Max. 2,953 characters (8-bit bytes) (23624 bits)
    Kanji/Kana  Max. 1,817 characters

As you have lower case, you'll be limited to 2953 chars, in fact less because of correction codes.

That should be enough for most VCards.

The example you show is 652 chars. So how is it you reach the limit ? Maybe it is more a char that cannot be encoded ?

.

the QRCode generated will no longer readable.

Do you mean it is generated but you cannot read it with the camera ?

Have you considered enlarging the QRCode image (in code, for display) ?

Tried.. No luck. It seems it won't even go beyond 500 characters. Here's my basic code:

textToQRCode = "BEGIN:VCARD\n" +
"N:\(lastName);\(firstName)\n" +
"TITLE:Admin \n" +
"TEL:\(phoneNumber)\n" +
"Email:\(email)\n" +
"ADR;WORK:;;\(street);\(city);\(state);\(zipCode);\(country) \n" +  //working
"NOTE:\(notes)\n" +
"END:VCARD"
 
if let qrImage = generateQRCode(textToQRCode) {
    imageBox.image =  qrImage
}
//
func generateQRCode(_ string: String)  -> UIImage? {

    let data = string.data(using: String.Encoding.utf8)  //for foreign characters

    if let QRFilter = CIFilter(name: "CIQRCodeGenerator") {
        QRFilter.setValue(data, forKey: "inputMessage")
        guard let QRImage = QRFilter.outputImage else {return nil}
        //To scale up the code without losing resolution
        let transformScale = CGAffineTransform(scaleX: 10, y: 10)
        let scaledQRImage = QRImage.transformed(by: transformScale)
        //processing to get the UIImage
        let context = CIContext()
        let cgImage = context.createCGImage(scaledQRImage, from: scaledQRImage.extent)
        let processedImage = UIImage(cgImage: cgImage!)
        //return processed image
        return processedImage
    }
    return nil
}

QRCode always generated (no character problems), but not readable by camera (or, other 3rd party reader), It will read when total characters count is small.

Is the exact textToQRCode the one you posted ? Could you show the maximum text that works ?

Could you post the image of the generated QRCode ?

This is the one generated and will work, add anymore character will not work..

Accepted Answer

Both QR code work. So I do not see what does not work. Could you show and explain such an example ?

I believe I've found the problem, its the printed code (image on top), not clear and fuzzy. Print is another matter. I will work on that. If problem I will start another request. Thanks.

QRCode for vCard
 
 
Q