Closed Shalling closed 11 years ago
This should usually just work fine. Are you sure that all the fields are according to the specification? I'm not totally sure about the use of uniqueid().
I use arrays and json_encode instead of manually formatted JSON in my application. Maybe I can push a version of the example.php
file using the same method in a couple of days.
Same problem here
$passJson = json_encode($passArray, JSON_NUMERIC_CHECK); $pass->setJSON($passJson);
works fine in a browser(file does open) but on iPhone safari can't download the file.
but when i use the same json string assigned in this script - it works and the pass open !?
$passJson = '{"formatVersion":1,"serialNumber":"320193-463-386","teamIdentifier":'.....}; $pass->setJSON($passJson);
some ideas?
@ptz0n : can you please push your example?
i found that when json_encode the array instead of primaryFields : [ { key: '', ...}, { ... }, { ... } ] it shows primaryFields: { "0" : { key: '', ... }, "1" : { ... }, "2" : { ... } }
any workaround on this issue?
Your array keys are not following the Passbook specification. The fields objects should always contain key
, label
and value
keys. The following PHP array;
json_encode(array(
'primaryFields' => array(
array(
'key' => 'origin',
'label' => 'From',
'value' => 'Stockholm C'
),
array(
'key' => 'destination',
'label' => 'To',
'value' => 'Göteborg C'
)
)
));
will give you:
{
"primaryFields":[
{
"key": "origin",
"label": "From",
"value": "Stockholm C"
},
{
"key": "destination",
"label": "To",
"value": "G\u00f6teborg C"
}
]
}
If it does not. What PHP (and JSON) version are you running?
@Shalling I have now submitted the pull request #22 regarding JSON encode from pass data formatted as PHP arrays.
i solved my problem.
i'm not sure but i guess i had two failures.
Great that you pointed out the JSON_NUMERIC_CHECK
constant. Good job getting it working!
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Due to I tried to use setJSON() by giving parameter from json_encode() and i got error on iPhone that "Safari can't download the file". So I would like to suggest some fixing for this to easily format the JSON, if it's possible.
For example <?php $json_data = array( "passTypeIdentifier" => "pass.com.example.passbook", "teamIdentifier" => "ABCDEFGHIJK", "formatVersion" => 1, "organizationName" => "Example", "serialNumber" => uniqid(), "backgroundColor" => "rgb(107,156,196)", "logoText" => "Company", "description" => "Demo Employee pass", "primaryFields" => array( array( 'key' => 'name', 'label' => 'Name', 'name' => $name, ), array( 'key' => 'lastName', 'label' => 'Last Name', 'lastName' => $lastName, ), array( 'key' => 'depart', 'label' => 'Depart', 'depart' => $depart, ), "barcode" => array( "format" => "PKBarcodeFormatQR", "message" => "Name: " . $name . " Last Name: " . $lastName . " Depart: " . $depart, "messageEncoding" => "iso-8859-1" ), ), ); $json = json_encode($json_data); $pass->setJSON($json);
?>