tschoffelen / php-pkpass

💳 PHP class for creating passes for Wallet on iOS.
https://includable.com
MIT License
916 stars 186 forks source link

Incorrect character rendering when scanning vCard QR code on iPhone #130

Open diegonicolas250 opened 1 year ago

diegonicolas250 commented 1 year ago

Hello, when scanning a QR code generated with vCard data on an iPhone device, the characters are not displayed correctly. This issue is specific to iPhone devices, as the QR code scans correctly on Android devices. The problem seems to be related to character encoding or rendering on iOS.

Code Snippet:

function vCard(User $user): string
{
    return "BEGIN:VCARD\r\n" .
        "VERSION:4.0\r\n" .
        "N:José María example;;\r\n" .
        "FN:{$user->fullName()}\r\n" .
        "TITLE:{$user->workPosition}\r\n" .
        "EMAIL;TYPE=work:{$user->email}\r\n" .
        "TEL;TYPE=\"voice,work\":{$user->phone}\r\n" .
        "ORG:TEST\r\n" .
        "END:VCARD\r\n";
}

$data = [
....
'barcode' => [
        'format' => 'PKBarcodeFormatQR',
        'message' => vCard($user),
        'messageEncoding' => 'iso-8859-1',
    ],
    'barcodes' => [
        [
            'format' => 'PKBarcodeFormatQR',
            'message' => vCard($user),
            'messageEncoding' => 'iso-8859-1',
        ],
    ],
...]

Actual Behavior

When I scan the QR with iPhone, the name displayed on the contact is Jos√© Mar√≠a instead of José María. I have tried changing the messageEncoding to UFT-8 but the result is the same.

Steps to reproduce

Steps to Reproduce:

  1. Generate a vCard QR code using the provided code snippet.
  2. Scan the generated QR code using the default iPhone camera app or a QR code scanning app.
  3. Observe that the characters in the scanned data are displayed incorrectly, with accent marks and special characters not rendered correctly.
tschoffelen commented 1 year ago

This is definitely a super interesting one! I don't think we do anything special when it comes to saving the JSON payload, we just json_encode it and save the file.

Could this be related to the vcard format itself?

https://stackoverflow.com/a/9222600/1129689