For getting the Latest Version of a Pass, GET request to webServiceURL/version/passes/passTypeIdentifier/serialNumber. What server do to respond to this request ? This is code I use:
if (strtoupper($_SERVER['REQUEST_METHOD']) === "GET" && $request[3]==='passes'){
$passTypeID = $request[4];
$serial = $request[5];
$auth_key = str_replace('ApplePass ', '', $headers['Authorization']);
}
Asked
Active
Viewed 487 times
0

Pradeep Pati
- 5,779
- 3
- 29
- 43

malinchhan
- 767
- 2
- 8
- 28
1 Answers
1
From the Apple Docs.
- If request is authorized, return HTTP status 200 with a payload of the pass data.
- If the request is not authorized, return HTTP status 401.
- Otherwise, return the appropriate standard HTTP status.
The "payload of the pass data" means the .pkpass bundle.

PassKit
- 12,231
- 5
- 57
- 75
-
I also saw this already ! but this point, I need to send . pkpass to device ? – malinchhan Apr 08 '13 at 04:15
-
Yes - if the .pkpass is now different to the .pkpass that is on the device then send the new .pkpass. Otherwise, just send a `304` "Not Modified" header. – PassKit Apr 08 '13 at 04:19
-
How can I know .pkpass on device is new or old ? – malinchhan Apr 08 '13 at 04:24
-
So this step, I need to send .pkpass directly or by push notification ? – malinchhan Apr 08 '13 at 04:35
-
before, I use: " – malinchhan Apr 08 '13 at 04:44
-
How to set header for'If-Modified-Since' ? I change like this: "str_replace('Last-Modified', $headers['If-Modified-Since']);" ,but not works! how can I change it ? – malinchhan Apr 08 '13 at 05:01
-
`If-Modified-Since` is a request header sent by the device - you do not send this header in the response. Instead, you need to set the `Last-Modified` header, then when the device next asks your web service for this file it will send a request with `If-Modified-Since: {value from your Last-Modified header }` – PassKit Apr 08 '13 at 05:14
-
now I get : Apr 8 15:05:00 CamMobs-iPod4 passd[21]
: Get serial #s task (for device b6a0503b6e034fc2db8173b4ad752e16, pass type pass.cam-mob.passbookpasstest, last updated 1365406354; with web service url http://192.168.1.202:8888/passesWebserver/) encountered error: Unexpected response code 304 – malinchhan Apr 08 '13 at 08:06 -
Because you are responding with `304` to the get serials method. This method expects a `204` if there are no serials that need updating. – PassKit Apr 08 '13 at 08:08
-
for getting the latest version of pass, what do I have to put for header: if-modified-since. I have this in this method: if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])){ //header('HTTP/1.0 304 Not Modified'); //exit; } – malinchhan Apr 08 '13 at 08:15
-
because there's no $_SERVER['HTTP_IF_MODIFIED_SINCE'], then I get : Apr 8 15:12:24 CamMobs-iPod4 passd[21]
: Get pass task (pass type pass.cam-mob.passbookpasstest, serial number 0001, if-modified-since (null); with web service url http://192.168.1.202:8888/passesWebserver/) got response with code 304 – malinchhan Apr 08 '13 at 08:17 -
but I also get this ; Apr 8 15:12:24 CamMobs-iPod4 passd[21]
: Get serial numbers task completed with update tag 1365408744, serial numbers ( 0001 ) – malinchhan Apr 08 '13 at 08:18 -
The header you send depends on whether or not you have an updated .pkpass bundle to send - if the bundle has not changed then just send a 304 header and exit, if the bundle has changed DO NOT send a 304, but you will need to send a whole bunch of headers with for the .pkpass file. – PassKit Apr 08 '13 at 08:18
-
Don't send a 304 header in response to the serials request, you should only send 304 in response to getting the latest version of a pass, and even then you should only send the 304 if the file has not been modified. – PassKit Apr 08 '13 at 08:20
-
my codes don't work! if (strtoupper($_SERVER['REQUEST_METHOD']) === "GET" && $request[3]==='passes'){ $passTypeID = $request[4]; $serial = $request[5]; $auth_key = str_replace('ApplePass ', '', $headers['Authorization']); if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])){ //header('HTTP/1.0 304 Not Modified'); //exit; } $querySelect = mysql_query("select * from registration"); $row = mysql_fetch_array($querySelect); if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])){ if ($passTypeID == $row['passTypeID'] && $serial ==$row['serialNo']){ – malinchhan Apr 08 '13 at 08:20
-
$pkpass_file = '/Applications/MAMP/htdocs/passesWebserver/DigiClubCardUpdated.pkpass'; header("Pragma: no-cache"); header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0"); header("Content-type: application/vnd.apple.pkpass; charset=UTF-8"); header('Content-Disposition:attachment; filename="genericPass.pkpass"'); – malinchhan Apr 08 '13 at 08:21
-
clearstatcache(); $filesize = filesize($pkpass_file); if ($filesize) header("Content-Length: ". $filesize); header('Content-Transfer-Encoding: binary'); if (filemtime($pkpass_file)) { date_default_timezone_set("UTC"); header('Last-Modified: ' . date("D, d M Y H:i:s", filemtime($pkpass_file)) . ' GMT'); } flush(); readfile($pkpass_file); response200(); }else{ response401(); } }else{ response304(); } } – malinchhan Apr 08 '13 at 08:22
-
Yes, your code is wrong - your if statement is not triggering so you are sending back an empty response. Please don't post code in comments. You have asked this question [here](http://stackoverflow.com/questions/15873076/how-to-respond-for-getting-pass-task), and there is already an answer showing what the problem is. – PassKit Apr 08 '13 at 08:24
-
ok ! now my pass is updated, but if-modified-since (null) ! why ? – malinchhan Apr 08 '13 at 08:28
-
what is advantage of if-modified-since ? – malinchhan Apr 08 '13 at 08:29
-
It is used to prevent your server from having to send (and the user's data plan from having to receive) a .pkpass bundle if the .pkpass bundle has not changed since the date provided in the `If-Modified-Since` header. In simple terms, Passbook is saying to your server please send me this .pkpass file but ONLY if it has not been modified since this date. It gets this date from the `Last-Modified` header that your server should send whenever it serves a .pkpass bundle. – PassKit Apr 08 '13 at 08:44
-
this header is not right. can you correct it ? (if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])){ //header('HTTP/1.0 304 Not Modified'); //exit; } ) – malinchhan Apr 08 '13 at 08:57
-
Your `header` and `exit` commands are commented out. Your logs are saying that Passbook is not sending `IF-MODIFIED-SINCE` (I.e. it is null), so this if statement will not trigger because because the superglobal $_SERVER['HTTP-IF-MODIFIED-SINCE'] will also not be set. – PassKit Apr 08 '13 at 09:00
-
now I can get header of if-modified-since: Apr 8 16:03:19 CamMobs-iPod4 passd[2236]
: Request contains header field – malinchhan Apr 08 '13 at 09:07 -
but I get this : Apr 8 16:03:19 CamMobs-iPod4 passd[2236]
: Web service error for pass.cam-mob.passbookpasstest (http://192.168.1.202:8888/passesWebserver/): Server requested update to serial number '0001', but the pass was unchanged. – malinchhan Apr 08 '13 at 09:08 -
when do I send .pkpass (what condition) ? – malinchhan Apr 08 '13 at 09:08
-
You control your .pkpass. If you publish a pass on Monday and then you decide to change it on Thursday. When your web server receives a request with an 'If-Modified-Since' Monday, you send the new pass (because you know it changed on Thursday). – PassKit Apr 08 '13 at 09:15
-
by your example , how I put the condition ? ( if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])== ...? ){ ..... } ) – malinchhan Apr 08 '13 at 09:19
-
how to put condition that it is difference from today ? – malinchhan Apr 08 '13 at 09:22
-
I don't know why it doesn't work now for getting a pass. This is from console: Apr 9 09:35:32 CamMobs-iPod4 passd[2880]
: Get pass task (pass type pass.cam-mob.passbookpasstest, serial number 0001, if-modified-since (null); with web service url http://192.168.1.202:8888/passesWebserver/) got response with code 404 – malinchhan Apr 09 '13 at 02:45 -
404 is not found - this implies that your re-write rule is broken. – PassKit Apr 09 '13 at 02:51
-
If I don't have any pass in my server, what should I change in header ? before I use ' header('Last-Modified: ' . date("D, d M Y H:i:s", filemtime('/Applications/MAMP/htdocs/passesWebserver/DigiClubCard.pkpass')) . ' GMT+07:00'); ' – malinchhan Apr 24 '13 at 02:35
-
I have answered your [other question](http://stackoverflow.com/questions/16182486/how-to-get-last-modified-of-the-pass-that-is-added-by-user-dynamically) on how to set the `Last-Modified` header. – PassKit Apr 24 '13 at 03:45