6

I have to integrate Passbook with a website that provides PDF417 barcodes with data encoded in binary (as opposed to text), such as this:

PDF17 barcode encoded in binary

Is there any way I can encode this binary chunk in pass.json so that Passbook displays it on the iPhone identically to the original picture?

Again, I cannot switch to text-based barcodes because I do not own the data. Just for clarification, the attached picture contains a PDF417 barcode that, when decoded, contains non-printable characters, such as the NULL character, which is why I refer to it as binary.

UPDATE

This is how the image decodes into a byte array:

01 00 01 00 02 00 E7 C4 B5 96 B8 42 94 B3 B4 75 
1A D1 F2 38 92 EA B5 0E 17 5D 0B 2A AA 64 18 CC 
28 62 86 E5 74 5D A3 89 09 12 6E D5 7A 1A C9 EE 
BF 23 9C E1 60 AD 9E DE 92 6D E5 79 99 C7 91 F1 
6A D5 82 2E B6 E3 81 24 F8 0A F8 E6 44 5D 56 D2 
00 00 00 00 00 00 40 0D 00 09 20 23 00 96 13 5C 
10 EC 0C EA A3 E8 A3 20 30 4B 2A 20 7D 0F BB DF 
F7 5E FA 1E 76 F7 40 20 10 08 04 02 81 40 20 30 
A3 D5 6C 1A 04 76 14 10

This is how I try to transform it into a utf-8 string:

{"message": "\u0001\u0000\u0001\u0000\u0002\u0000\u00E7\u00C4\u00B5\u0096\u00B8\u0042\u0094\u00B3\u00B4\u0075\u001A\u00D1\u00F2\u0038\u0092\u00EA\u00B5\u000E\u0017\u005D\u000B\u002A\u00AA\u0064\u0018\u00CC\u0028\u0062\u0086\u00E5\u0074\u005D\u00A3\u0089\u0009\u0012\u006E\u00D5\u007A\u001A\u00C9\u00EE\u00BF\u0023\u009C\u00E1\u0060\u00AD\u009E\u00DE\u0092\u006D\u00E5\u0079\u0099\u00C7\u0091\u00F1\u006A\u00D5\u0082\u002E\u00B6\u00E3\u0081\u0024\u00F8\u000A\u00F8\u00E6\u0044\u005D\u0056\u00D2\u0000\u0000\u0000\u0000\u0000\u0000\u0040\u000D\u0000\u0009\u0020\u0023\u0000\u0096\u0013\u005C\u0010\u00EC\u000C\u00EA\u00A3\u00E8\u00A3\u0020\u0030\u004B\u002A\u0020\u007D\u000F\u00BB\u00DF\u00F7\u005E\u00FA\u001E\u0076\u00F7\u0040\u0020\u0010\u0008\u0004\u0002\u0081\u0040\u0020\u0030\u00A3\u00D5\u006C\u001A\u0004\u0076\u0014\u0010";}

However, Passbook does not display an equivalent barcode. In fact, it displays just a few first bytes.

Kerido
  • 2,930
  • 2
  • 21
  • 34
  • Even if you do not own the data, maybe you could get access to the binary encoding format? The you should be able to decode the data and pass it as text to PassBook. – Johan Karlsson Nov 13 '13 at 13:29
  • @Johan Karlsson: I can decode the pass. As a result, I am getting a binary byte array containing zeroes at the beginning. The problem is, I do not know how to pass this byte array to **pass.json**. – Kerido Nov 13 '13 at 13:32
  • yes you can encode the bitstream what code have you tried and where is it failing you? – PassKit Nov 13 '13 at 14:05
  • 2
    @PassKit: Let's say the barcode on the attached picture decrypts as: 0x00, 0x01, 0x00, 0x02 (these are example four bytes). How would I populate a JSON field that expects a string: `{"message": "WHAT GOES HERE?" }` – Kerido Nov 13 '13 at 14:29
  • 1
    This will depend on the encoding - you simply encode the byte stream in your chosen encoding. How are you currently generating and signing your passes? Perhaps I can provide some code to demonstrate. – PassKit Nov 14 '13 at 03:01
  • @PassKit: I added an update that may further clarify the problem. Any ideas? – Kerido Nov 17 '13 at 07:57
  • Have you tried using using messageEncoding to 'iso-8859-1' and set message to the binary data encoded as iso-8850-1 string? What PDF417 scanner do you use to test the barcode ? (since Passbook on iOS7 at least will produce PDF417 barcode in much wider and shorter image than your example) – alphageek Nov 19 '13 at 00:55
  • why you cant encode the byte array as base64 and then decode it to get you binary data again? – Javier Neyra Nov 22 '13 at 17:54
  • you should probably read this... http://stackoverflow.com/questions/1443158/binary-data-in-json-string-something-better-than-base64 – Javier Neyra Nov 22 '13 at 18:03
  • 2
    Someone deleted my answer, so… I guess they don't think it was an answer? Did you try it on an actual iPhone, or dropping it in the sim? Your escaped string displays a correct barcode for me on the actual iPhone, and is truncated on the Mac. That's a bug, but shouldn't matter much. – Ken Nov 23 '13 at 06:20
  • What @Ken notes is spot on. I would encourage you to report the bug you're seeing on the Mac, however. – Stephen Canon Nov 24 '13 at 21:31

1 Answers1

0

I don't think you want to decode the binary data of the image, but instead want to read the data from the barcode as if it were scanned.

You could use a service like http://zxing.org/w/decode.jspx which gives you the value of the barcode as if it were being scanned.

Send the 'Raw Text' value to pass.json.

I haven't used this service, but after a quick read I'm assuming it goes in 'message' below:

"barcode" : {
    "message" : "ABCD 123 EFGH 456 IJKL 789 MNOP",
    "format" : "PKBarcodeFormatPDF417",
    "messageEncoding" : "iso-8859-1"
}

ref: https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/PassKit_PG/Chapters/Creating.html#//apple_ref/doc/uid/TP40012195-CH4-SW1

Rots
  • 5,506
  • 3
  • 43
  • 51
  • 2
    Correct, however, the image attached does not decode to a human-readable string. Instead, it looks more like a binary chunk with NULL-characters and other special characters. These bytes don't paste well into the value of the `"message"` field. – Kerido Nov 22 '13 at 11:42
  • PDF417 uses a base 929 encoding. Try converting the returned data from base 929 to 64 or something else relevant for the message format. ref: http://en.wikipedia.org/wiki/PDF417 – Rots Nov 23 '13 at 02:19