ApnsServer.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. require_once 'Zend/Mobile/Push/Apns.php';
  3. require_once 'Zend/Mobile/Push/Message/Apns.php';
  4. $message = new Zend_Mobile_Push_Message_Apns();
  5. $message->setAlert('Zend Mobile Push Example');
  6. $message->setBadge(1);
  7. $message->setSound('default');
  8. $message->setId(time());
  9. $message->setToken('ABCDEF0123456789');
  10. $apns = new Zend_Mobile_Push_Apns();
  11. $apns->setCertificate('/path/to/provisioning-certificate.pem');
  12. try {
  13. $apns->connect(Zend_Mobile_Push_Apns::SERVER_SANDBOX_URI);
  14. } catch (Zend_Mobile_Push_Exception_ServerUnavailable $e) {
  15. // you can either attempt to reconnect here or try again later
  16. exit(1);
  17. } catch (Zend_Mobile_Push_Exception $e) {
  18. echo 'APNS Connection Error:' . $e->getMessage();
  19. exit(1);
  20. }
  21. try {
  22. $apns->send($message);
  23. } catch (Zend_Mobile_Push_Exception_InvalidToken $e) {
  24. // you would likely want to remove the token from being sent to again
  25. echo $e->getMessage();
  26. } catch (Zend_Mobile_Push_Exception $e) {
  27. // all other exceptions only require action to be sent
  28. echo $e->getMessage();
  29. }
  30. $apns->close();