3

I have generated PASS with my code and also get device id, pushtoken in response from device.

here is code by which I am store all device and Pass information in database.

   $params = array(
                    "get"=>$_GET,
                    "request"=>$_REQUEST,
                    "post"=>$_POST,
                    "server"=>$_SERVER
                );
$url = $_SERVER['SCRIPT_URI'];
$myfile = file_put_contents('callback.txt', json_encode($params).PHP_EOL , FILE_APPEND | LOCK_EX);
$content = trim(file_get_contents("php://input"));
$myfile = file_put_contents('log.txt', $content.PHP_EOL , FILE_APPEND | LOCK_EX);
$header = json_encode(getallheaders());
$myfile = file_put_contents('header.txt', $header.PHP_EOL , FILE_APPEND | LOCK_EX);



/*
 * store registered device data
 * */

$str = $_SERVER['SCRIPT_URI'];
$str = stripslashes($str);


$url_slot = parse_url($str);
$urlArray = explode('/',$url_slot['path']);
$passid = $urlArray['11']; // serial no
$deviceId = $urlArray['8'];
$passtype = $urlArray['10'];
try {
    $dbh = new PDO('mysql:host=localhost;dbname=''', 'yyyy', 'zzzz');


    $stmt = $dbh->prepare("INSERT INTO devices_passes (device_id, pass_id, pass_type, created, modified) VALUES
(:device_id,:pass_id,:pass_type,:created,:modified)");
    $stmt->bindParam(':device_id', $device_id);
    $stmt->bindParam(':pass_id', $pass_id);
    $stmt->bindParam(':pass_type', $pass_type);
    $stmt->bindParam(':created', date('d-m-y'));
    $stmt->bindParam(':modified', date('d-m-y'));

    $device_id = $deviceId;
    $pass_id = $passid;
    $pass_type = $passtype;

    $stmt->execute();
    $dbh = null;
} catch (PDOException $e) {
    print "Error!: " . $e->getMessage() . "<br/>";
    die();
}



try {
    $dbh = new PDO('mysql:host=localhost;dbname=yyyy', 'uuuuu', 'yyyyyy');
    $stmt = $dbh->prepare("INSERT INTO devices (push_token) VALUES
(:push_token)");
    $stmt->bindParam(':push_token', $push_token);
    $push_token = $content['pushToken'];
    $stmt->execute();
    $dbh = null;
} catch (PDOException $e) {
    print "Error!: " . $e->getMessage() . "<br/>";
    die();
}

But when I send push notification to device , it will not reflect anything in device. here is code of sending push notification to device.

<?php
$apnsHost = 'gateway.push.apple.com';
$apnsPort = 2195;
$apnsCert = 'apple_push_notification_production.pem';
$push_token = 'my token';
$passIdentify = 'pass.yyyyy.xxxx';

$payload = '{}';
$msg = chr(0) . pack('n', 32) . pack('H*', $push_token) . pack('n', strlen($payload)) . $payload . pack('n', strlen($passIdentify)) . $passIdentify;

$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);

$apns = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $error, $errorString, 2, STREAM_CLIENT_CONNECT, $streamContext);

fwrite($apns, $msg);

@socket_close($apns);
fclose($apns);

?>

Can you please help me when I am going wrong ??

Kruti Aparnathi
  • 175
  • 1
  • 11
  • Check my answer [here](http://stackoverflow.com/questions/15877496/how-to-make-a-push-notification-for-a-pass) for a checklist. You need to make sure that you have the change message set, and that the new pass content is different to the old pass content. – PassKit Apr 27 '17 at 10:45
  • where can I add changeMessage parameter ? sending notification ?? – Kruti Aparnathi Apr 27 '17 at 10:51
  • I got your point but if I generate updated .pkpass file how device get know about that update ? – Kruti Aparnathi Apr 27 '17 at 11:23
  • You add it in the new pass' `pass.json` – PassKit Apr 27 '17 at 11:24
  • yes but how device get automatic update. right now first time when I send link to device by mail and when hit the link pass will be generated and ask to add in wallet or not . so how can I send updated pass ? – Kruti Aparnathi Apr 27 '17 at 11:26
  • It's all in the documentation - you need to implement the other parts of the web service for the device to be able to pull the latest version from your server. Step one would be having the pass update when you pull down on the back of the pass. – PassKit Apr 28 '17 at 04:25
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/142882/discussion-between-kruti-aparnathi-and-passkit). – Kruti Aparnathi Apr 28 '17 at 07:27
  • device is not sending me this request GET request to webServiceURL/version/devices/deviceLibraryIdentifier/registrations/passTypeIdentifier?passesUpdatedSince=tag – Kruti Aparnathi Apr 28 '17 at 07:48
  • It will send a request to get serials first – PassKit Apr 28 '17 at 07:49
  • yes I have send serials $curl_post_data = "{ lastUpdate: $lastupdate, serialNumbers: ['738489']}"; on this url $service_url = 'http://www.webclueslab.com/qa/skywire/passAPI-ios/examples/callback.php/v1/devices/9e17fb1bf487de153e9e17bf7ae5fafb/registrations/pass.webclues.testSkywire/738489'; – Kruti Aparnathi Apr 28 '17 at 08:02
  • I am not getting where I am wrong... – Kruti Aparnathi Apr 28 '17 at 08:03
  • Have you implemented all the endpoints for he web service, including the logging endpoint. Also try watching the iPhone logs in the console as you send the push. – PassKit Apr 28 '17 at 08:28
  • what is logging endpoint do u mean authentication token verification? – Kruti Aparnathi Apr 28 '17 at 09:09
  • The logging endpoint is part of the PassKit web service you need to provide yourself, see the [PassKit Web Service Reference](https://developer.apple.com/library/content/documentation/PassKit/Reference/PassKit_WebService/WebService.html#//apple_ref/doc/uid/TP40011988-CH0-SW7) for more information. – mbaechtold Apr 28 '17 at 11:06
  • I was referring this document https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/PassKit_PG/Updating.html generating PAS first then device respond me with registration. I have stored device id and push token in my database and then I was trying to send notification code using above code , so now device should call https:////devices/ /registrations/?passesUpdatedSince= webservice so I can provide updated pass identifier. but my webservice is not getting passesUpdatedSince. what is going wrong here please help – Kruti Aparnathi Apr 28 '17 at 11:33
  • You won't see that parameter on the first request. Only on subsequent requests after you have delivered a pass including a last updated header – PassKit Apr 29 '17 at 11:32
  • https://developer.apple.com/library/content/documentation/PassKit/Reference/PassKit_WebService/WebService.html#//apple_ref/doc/uid/TP40011988 you should be using this document. – PassKit Apr 29 '17 at 11:34
  • do you have final code? is it working now? – Michael Aug 24 '17 at 18:11

0 Answers0