问题
I am playing with apples Passbook service. I have a really strange behaviour on all devices. If I send a push via APNS to the device to let them know that there is a update for a certain pass they do the update but they do not show any notification on the Lockscreen on the device.
Right now I am logging the whole communication between my PHP-Webservice and the APNS. I always answer with headre 200, and the requested answer. (1st Serials; 2nd Pass.pkpass) and the device does the update as I can see in the passbook app but as I already said I do not get any Notification on the Lockscreen. The Device is set up correctly as described in this article: a link
and I do my APNS Request like this:
public function sendePushNotification($passTypeID, $debug = true)
{
// Zertifikat vorhanden ?
$certFullPath = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . "api/cert/ck.pem";
if (file_exists($certFullPath))
{
/**
* Payload vorbereiten
*/
$message = 'PASSDROP UPDATE';
$body = array();
$body['aps'] = array('alert' => $message);
/**
* Host bestimmen
*/
$apnsHost = "gateway.push.apple.com"; // Development Umgbung
/**
* Stream erstellen
*/
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', $certFullPath);
$fp = stream_socket_client('ssl://' . $apnsHost . ':2195', $err, $errstr, 2, STREAM_CLIENT_CONNECT, $ctx);
if (!$fp)
{
echo "Fehler beim APNS: " . $err . " / ". $errstr. "\n";
return false;
}
/**
* Payload versenden
*/
$payload = json_encode($body);
$msg = chr(0) . pack("n",32) . pack('H*', str_replace(' ', '', $this->token)) . pack("n",strlen($payload)) . $payload;
}
else
{
throw new Exception("Zertifikat-Bundle " . $certFullPath . " existiert nicht !!!");
}
}
As far as I know Apple does not read the payload when pushing a Pass in Passbook.
Does anybody have a hint for me what I can try next? Do I need anything in the pass.json file?
回答1:
If your devices are updating and receiving the new passes, but you are not seeing a notification then it is most likely that your pass.json doesn't contain a changeMessage key.
In order for a notification to display:
- a pass data value must have changed (field labels, colours and images do not trigger updates), and
- the changed field must include the changeMessage key, preferably with a %@ placeholder that will be replaced with the new field value.
For Passbook, the APNS push's only purpose is to notify the device that the web service has fresh content. All notification activity is determined by the differences between the old and new pass.json files.
If your pass field is changing, and you have a changeMessage key set but you are not seeing a notification, then posting the relevant before and after sections of pass.json may help us identify what's wrong.
The json excerpts below will trigger the follwoing two notifications when the 'after' pass replaces the 'before' pass:
- Please proceed to gate 22
- Flight Status: Boarding
Before pass:
"boardingPass": {
"headerFields": [{
"key": "h1",
"value": "--",
"label": "Gate",
"changeMessage": "Please proceed to gate %@"
}, {
"key": "h2",
"value": "On Time",
"label": "Status",
"changeMessage": "Flight status: %@"
}],
...
After pass:
"boardingPass": {
"headerFields": [{
"key": "h1",
"value": "22",
"label": "Gate",
"changeMessage": "Please proceed to gate %@"
}, {
"key": "h2",
"value": "Boarding",
"label": "Status",
"changeMessage": "Flight status: %@"
}],
...
来源:https://stackoverflow.com/questions/15209815/passbook-update-push-not-shown-on-lockscreen