APNS-PHP & PassBook

2,016 views
Skip to first unread message

mart...@gmail.com

unread,
Oct 16, 2012, 4:04:36 AM10/16/12
to apns...@googlegroups.com
i have been working for a week on a project that implements a dynamic pass for passbook, i am trying to use APNS-php to send notifications to passbook.
i have a hard time finding good documentation about this.

i'm using the same certificate for APNS as for signing the passes.
but, despite the fact that i'm not getting any error messages my notifications are not received by my iPhone.


i send it like this:

$push_service = new ApnsPHP_Push(
ApnsPHP_Abstract::ENVIRONMENT_SANDBOX,
PROJECT_ROOT . "/Passes/$passTypeIdentifier/APNS.pem"
);

// Set the Root Certificate Autority to verify the Apple remote peer
$push_service->setRootCertificationAuthority('src/Emakina/Notifications/ApnsPHP/entrust_root_certification_authority.pem');
// Connect to the Apple Push Notification Service
$push_service->connect();

$message = new ApnsPHP_Message($pushToken);
$push_service->add($message);
$push_service->send();
// Disconnect from the Apple Push Notification Service
$push_service->disconnect();
// Examine the error message container
$aErrorQueue = $push_service->getErrors();
if (!empty($aErrorQueue)) {
var_dump($aErrorQueue);
}
----
do you think i'm right to use the same certicate (converted to a .pem file) for APNS and .pkpass generation ?
APNS notifications for passbook are supposed to be empty, but, even if i don't set any properties for my messages, i still see a tiny payload, a tiny fragment of JSON,

mic...@cairnsrecipes.com

unread,
Oct 19, 2012, 8:50:15 PM10/19/12
to apns...@googlegroups.com
I am in a similar boat, the code I am using however is as follows:

        $q2="SELECT pushtoken FROM devices WHERE id='deviceid'";
        $r2=$this->db->query($q2); 
                                        require_once 'ApnsPHP/Autoload.php';
                $push = new ApnsPHP_Push(
       ApnsPHP_Abstract::ENVIRONMENT_SANDBOX,
       'mypassbookcoupon.pem' //as defined in the passbook documentation, use the same certificate that is used to sign the passes
);
$push->setRootCertificationAuthority('entrust.pem'); //as downloaded from entrust.
$push->connect();
while ($row2 = $r2->fetchColumn()) {
$message = new ApnsPHP_Message(''.$row2.'');
$message->setCustomProperty(''); //blank json payload as defined in passbook documentation (is this correct?)
print_r($message);
$push->add($message);
$push->send();
}
$push->disconnect();
$aErrorQueue = $push->getErrors();
if (!empty($aErrorQueue)) {
       var_dump($aErrorQueue);
}

The result I get when testing is as follows:

  1. Sat, 20 Oct 2012 11:29:01 +1100 ApnsPHP[8316]: INFO: Trying ssl://gateway.sandbox.push.apple.com:2195...
  2. Sat, 20 Oct 2012 11:29:02 +1100 ApnsPHP[8316]: INFO: Connected to ssl://gateway.sandbox.push.apple.com:2195.
  3. Warning: Missing argument 2 for ApnsPHP_Message::setCustomProperty(), called in /var/www/pbrest/DB_Mysql.php on line 144 and defined in /var/www/pbrest/ApnsPHP/Message.php on line 196
  4. Notice: Undefined variable: mValue in /var/www/pbrest/ApnsPHP/Message.php on line 203
  5. ApnsPHP_Message Object
  6. (
  7. [_bAutoAdjustLongPayload:protected] => 1
  8. [_aDeviceTokens:protected] => Array
  9. (
  10. [0] => thereisabiglongpushtokenherebutiremoveditforsecurity
  11. )
  12. [_sText:protected] =>
  13. [_nBadge:protected] =>
  14. [_sSound:protected] =>
  15. [_aCustomProperties:protected] => Array
  16. (
  17. [] =>
  18. )
  19. [_nExpiryValue:protected] => 604800
  20. [_mCustomIdentifier:protected] =>
  21. )
  22. Sat, 20 Oct 2012 11:29:02 +1100 ApnsPHP[8316]: INFO: Sending messages queue, run #1: 1 message(s) left in queue.
  23. Sat, 20 Oct 2012 11:29:02 +1100 ApnsPHP[8316]: STATUS: Sending message ID 1 [custom identifier: unset] (1/3): 63 bytes.
  24. Sat, 20 Oct 2012 11:29:02 +1100 ApnsPHP[8316]: INFO: Disconnected.

When I check for feedback, I receive nothing.

  1. Sat, 20 Oct 2012 10:30:49 +1000 ApnsPHP[16661]: INFO: Trying ssl://feedback.sandbox.push.apple.com:2196...
  2. Sat, 20 Oct 2012 10:30:50 +1000 ApnsPHP[16661]: INFO: Connected to ssl://feedback.sandbox.push.apple.com:2196.
  3. Sat, 20 Oct 2012 10:30:50 +1000 ApnsPHP[16661]: INFO: Reading...
  4. Sat, 20 Oct 2012 10:30:50 +1000 ApnsPHP[16661]: INFO: Disconnected.

Luca Rocchi

unread,
Oct 21, 2012, 5:58:10 PM10/21/12
to apns...@googlegroups.com
i was in that situation like you just some hours ago ... you should switch to production enviroment  , as you can read in Apple Passbook forum , Passbook notification are not delivered by development server only ssl://gateway.push.apple.com:2195 works

So that are the step
1) change ENVIRONMENT_SANDBOX to PRODUCTION
2) get a distribution provisioning profile set to Ad Hoc from Apple and rebuild your app
3) generate  a server_certificates_bundle_production.pem
so far as i know it seems that with Ad How distribution we miss the debugging support by xcode

After that device start receiving notification
By the way im stuck  how i should continue , so in the case , let me know :)

Martijn Scheffer

unread,
Oct 21, 2012, 6:12:20 PM10/21/12
to apns...@googlegroups.com
yes i think passbook only uses production certificates (i'm not the one in charge of making them within my team, so i can't be 100% sure)

no need to call "setCustomProperty('')", firstly i'm not sure that clears the JSON completely, secondly i think the APNS server completely ignores the JSON, it is unclear in the documentation, they seem to imply that the JSON HAS to be empty, i don't think that is actually the case. the certificate tells apple that the notification is for a pass, that's all the information they need.

Martijn Scheffer

unread,
Oct 21, 2012, 6:14:46 PM10/21/12
to apns...@googlegroups.com
1) setCustomProperty takes two arguments.
2) you don't have to call setCustomProperty
3) i think passes only work with the production server, not the sandbox.

Luca Rocchi

unread,
Oct 23, 2012, 5:02:42 PM10/23/12
to apns...@googlegroups.com
Just to let you know that i realize there is not need to create ad hoc distribution to run Passbook app and get notifications , everything works with developer certificate as well

e.p...@gmail.com

unread,
Nov 10, 2012, 6:53:11 AM11/10/12
to apns...@googlegroups.com
I just for clarity:
  • What push certificate should be used when sending push notifications to Passbook? I think it's the Pass Type ID certificate, but it's not working for me.
  • Connecting with APNS works fine, but device(s) are not receiving any push notifications.
  • The feedback service does not provide any errors.
  • I'm using the PRODUCTION environment.
I think Apple needs to provide better troubleshooting methods when dealing with push notifications. Any ideas on how to trace the problem?

Thx!

PS. I noticed that my devices are receiving very few notifications (Twitter, Facebook etc.). Are you also experiencing problems with push right now? DS.

Luca Rocchi

unread,
Nov 10, 2012, 7:24:48 AM11/10/12
to apns...@googlegroups.com, e.p...@gmail.com
Hi
As i finally made it working , i can give you some hints

1 What push certificate should be used when sending push notifications to Passbook? I think it's the Pass Type ID certificate, but it's not working for me.

This is correct , no doubt , the APN is from your server and Passbook not you App

2) Connecting with APNS works fine, but device(s) are not receiving any push notification
Until everything will correct you do not get notification so be sure everything is ok step by step .. check also to add changeMessage to field as this
              "primaryFields": [
               {
               "key" : "bonus",
               "label" : "bonus points",
               "value" : "'.$rec->bonus.'",
            "changeMessage":"Bonus changed to %@."
              }

3) The feedback service does not provide any errors.

To get errors enable logging on device -Setting - Developer - Passkit testing and check Addition Logging ... also Allow HTTP service make it easy , you can switch to test on HTTPS after , in this case also set webServiceURL to http:// ...
Then go to XCode  Organizer - Console ... log from Passkit are there


4) I'm using the PRODUCTION environment.

OK

Martijn Scheffer

unread,
Nov 10, 2012, 7:33:41 AM11/10/12
to apns...@googlegroups.com, e.p...@gmail.com
i didn't follow the whole conversation, but i noticed this:

"ENVIRONMENT_SANDBOX,"

that's not right.

i use a .pem file, made using this explanation, 


i have not had any problems since i started following those instructions, making 4 passes without any problems

Martin

Martijn Scheffer

unread,
Nov 10, 2012, 7:34:45 AM11/10/12
to apns...@googlegroups.com, e.p...@gmail.com
"ENVIRONMENT_SANDBOX,"

OK, that was my code :D

Martijn Scheffer

unread,
Nov 10, 2012, 7:38:51 AM11/10/12
to apns...@googlegroups.com, e.p...@gmail.com
another thing that can cause problems is syntax errors in the json.

to debug those i connect the iPhone (in dev mode) to XCode, i activate "additional logging" in the developer settings on the iPhone.

a good trick to check if your pass is actually correct is to download it using chrome (or any other browser but safari), change the .pkpass to .zip, and check the contents.

you can also check if the pass is correct, by reloading it manualy from within passbook (after changing the modification date on the server)

but the first step would be to make your .pem file again, just to be sure it's OK.

sorry for all those mails, and good luck :)

e.p...@gmail.com

unread,
Nov 10, 2012, 7:57:35 AM11/10/12
to apns...@googlegroups.com
It was actually my web service (API) implementation that was the error for me. Using Charles Proxy to sniff traffic from Passbook making it clear for me.

The push message to APNS should not have any additional body, just the push token (receiver).


Den tisdagen den 16:e oktober 2012 kl. 10:04:37 UTC+2 skrev Martijn Scheffer:

Martijn Scheffer

unread,
Nov 10, 2012, 8:14:03 AM11/10/12
to apns...@googlegroups.com
On Sat, Nov 10, 2012 at 1:57 PM, <e.p...@gmail.com> wrote:
It was actually my web service (API) implementation that was the error for me. Using Charles Proxy to sniff traffic from Passbook making it clear for me.

The push message to APNS should not have any additional body, just the push token (receiver).



yep (in that example "message" was a empty string), that was very early attempt, now i just do :

$push_service = new ApnsPHP_Push(ApnsPHP_Abstract::ENVIRONMENT_PRODUCTION, 'APNS.pem');
$push_service->setRootCertificationAuthority('entrust_root_certification_authority.pem');
$push_service->connect();

$message = new ApnsPHP_Message($pushToken);
$push_service->add($message);

$push_service->send();
$push_service->disconnect();

rac...@gmail.com

unread,
Dec 18, 2012, 4:46:35 AM12/18/12
to apns...@googlegroups.com

rac...@gmail.com

unread,
Dec 18, 2012, 4:57:18 AM12/18/12
to apns...@googlegroups.com, rac...@gmail.com
Hi ,

Im working on a php application wich interact with passbook.
I tried to use sandbox environement with a developpement certificate.
It return me an error "invalid token (8)".

Then i there (thank you) in passbook case , I can only use production environement;
So I tried to generate a distribution certificate from apple provisionning portal (im not sur that i have the good one).

I test your code : sample_push.php

root@mimo-15910:/home/www/apn/ApnsPHP# php sample_push.php 
Tue, 18 Dec 2012 10:36:43 +0100 ApnsPHP[26074]: INFO: Trying ssl://gateway.push.apple.com:2195...
Tue, 18 Dec 2012 10:36:49 +0100 ApnsPHP[26074]: INFO: Connected to ssl://gateway.push.apple.com:2195.
Tue, 18 Dec 2012 10:36:49 +0100 ApnsPHP[26074]: INFO: Sending messages queue, run #1: 1 message(s) left in queue.
Tue, 18 Dec 2012 10:36:49 +0100 ApnsPHP[26074]: STATUS: Sending message ID 1 [custom identifier: Message-Badge-3] (1/3): 293 bytes.
Tue, 18 Dec 2012 10:36:50 +0100 ApnsPHP[26074]: INFO: Disconnected.
root@mimo-15910:/home/www/apn/ApnsPHP# 

But didn't receive any push .


Here the code of sample_push.php:


......

error_reporting(-1);

// Using Autoload all classes are loaded on-demand
require_once 'ApnsPHP/Autoload.php';

// Instanciate a new ApnsPHP_Push object
$push = new ApnsPHP_Push(
    ApnsPHP_Abstract::ENVIRONMENT_PRODUCTION,
    'server_certificate_bundle_prod.pem'
);

// Set the Provider Certificate passphrase
// $push->setProviderCertificatePassphrase('test');

// Set the Root Certificate Autority to verify the Apple remote peer
//$push->setRootCertificationAuthority('entrust_root_certification_authority.pem');

// Connect to the Apple Push Notification Service
$push->connect();

// Instantiate a new Message with a single recipient
//$message = new ApnsPHP_Message('1e82db91c7ceddd72bf33d74ae052ac9c84a065b35148ac401388843106a7485');
//$message = new ApnsPHP_Message('4b9b0c9a7eba1d3d2b47862d48888240f01772a8d33fcf01c9d9401d77bb4bd4');
//$message  =   new ApnsPHP_Message('4b9b0c9a7eba1d3d2b47862d48888240f01772a8d33fcf01c9d9401d77bb4bd4');
$message = new ApnsPHP_Message('4b9b0c9a7eba1d3d2b47862d48888240f01772a8d33fcf01c9d9401d77bb4bd4');


// Set a custom identifier. To get back this identifier use the getCustomIdentifier() method
// over a ApnsPHP_Message object retrieved with the getErrors() message.
$message->setCustomIdentifier("Message-Badge-3");

// Set badge icon to "3"
$message->setBadge(3);

....

It doesnt generate me any error but i didnt receive any push.

So I have some questions : 

1-/ Does the way i generate production certificate is same as developpement;
2- / How can I verify certificate production.
3-/ I didnt send any message specific to passbook can it be the reason i didnt receive any push.



Im on it from 1 week without any result, can you help me please.

Thank you .

Rachid

Luca Rocchi

unread,
Dec 18, 2012, 4:59:44 AM12/18/12
to apns...@googlegroups.com
have you added changedMessage on passbook json field ?
--
Luca Rocchi
http://www.mobileborg.com



Luca Rocchi

unread,
Dec 18, 2012, 5:04:08 AM12/18/12
to apns...@googlegroups.com
i mean changeMessage not changedMessage

      {
          "key": "status",                                                   
          "label": "status",
          "value":"'.self::$rec->status.'",
          "changeMessage":"Status changed to %@."
      },

rac...@gmail.com

unread,
Dec 18, 2012, 5:36:41 AM12/18/12
to apns...@googlegroups.com
Hi Thank you for your quick response ,

Do I have to put it on this initial pass ?


Rachid

Luca Rocchi

unread,
Dec 18, 2012, 7:54:47 AM12/18/12
to apns...@googlegroups.com
yes you have to put it in the json while buinding up the pass , in additon to field value label and key

rac...@gmail.com

unread,
Dec 18, 2012, 12:04:45 PM12/18/12
to apns...@googlegroups.com
Thank you.
Ill test it.

Rachid
Message has been deleted

ehsan.ul...@gmail.com

unread,
Apr 28, 2014, 6:02:28 AM4/28/14
to apns...@googlegroups.com
I want to send push notification to passbook that I have the latest version of specific coupon, who can I implement this with APNS-PHP, currently i am using the PRODUCTION Environment with .pem certificate. 

Using these settings I can send push notification to device successfully, with alert etc. but with passbook its not receiving any notification.
I am sending the empty payload as suggested by the apple docs. 
how can i use the pass type identifier and token while sending push notification to passbook.

edw...@actv8.me

unread,
Dec 5, 2014, 7:00:16 PM12/5/14
to apns...@googlegroups.com
Hi,
you have mentioned that your are using the same certificate for APNS as for signing the passes.
how can you do that.
i'm have the same problem, everything seems its working but i am not getting the notification, and my certificates are different
thanks

Martijn Scheffer

unread,
Dec 7, 2014, 3:10:05 AM12/7/14
to apns...@googlegroups.com
i'm sorry but this is so long ago, i don't remember anything.

--
You received this message because you are subscribed to a topic in the Google Groups "apns-php" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/apns-php/AChGyVwH7Zc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to apns-php+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

bern...@gmail.com

unread,
Jun 18, 2015, 5:20:48 PM6/18/15
to apns...@googlegroups.com
up!
Reply all
Reply to author
Forward
0 new messages