<?php include_once __DIR__ . '/../autoload.php'; if (!class_exists('AMQPConnection')) { \Demo::error('Please install PHP Amqp Extension for run this demo (AMQP Queue).'); } use Apple\ApnPush\Notification\Notification; use Apple\ApnPush\Notification\Message; use Apple\ApnPush\Notification\Connection; use Apple\ApnPush\Queue\Amqp; // Create connection $connection = new Connection(CERTIFICATE_FILE, PASS_PHRASE, SANDBOX_MODE); // Create notification $notification = new Notification($connection); // Create message $message = new Message(); $message->setBody('[Amqp queue] Hello world')->setDeviceToken(DEVICE_TOKEN); // Create amqp queue and send message $amqp = Amqp::create($notification); $amqp->addMessage($message);
<?php include_once __DIR__ . '/../autoload.php'; if (!class_exists('Redis')) { \Demo::error('Please install PHP Redis Extension for run this demo (Redis Queue).'); } use Apple\ApnPush\Notification\Notification; use Apple\ApnPush\Notification\Connection; use Apple\ApnPush\Queue\Redis; // Create connection $connection = new Connection(CERTIFICATE_FILE, PASS_PHRASE, SANDBOX_MODE); // Create notification $notification = new Notification($connection); // Create amqp queue $amqp = Redis::create($notification); $amqp->runReceiver();
<?php include_once __DIR__ . '/../autoload.php'; if (!interface_exists('Psr\\Log\\LoggerInterface')) { \Demo::error('Please install "psr/log" for run this demo (Notification with logger system).'); } include_once __DIR__ . '/CustomLogger.php'; use Apple\ApnPush\Certificate\Certificate; use Apple\ApnPush\Notification\Notification; use Apple\ApnPush\Notification\Connection; use Apple\ApnPush\Notification\SendException; // Create connection $certificate = new Certificate(CERTIFICATE_FILE, PASS_PHRASE); $connection = new Connection($certificate, SANDBOX_MODE); // Create custom logger $logger = new CustomLogger(); // Create notification $notification = new Notification(); $notification->setLogger($logger)->setConnection($connection); // Send to correct device token $notification->sendMessage(DEVICE_TOKEN, '[Correct] Hello'); try { // Send to incorrect device token $notification->sendMessage(str_repeat('a', 64), '[Incorrect] Hello'); } catch (SendException $e) { } $notification->sendMessage(DEVICE_TOKEN, '[Correct] Hello 2 ;)');
<?php include_once __DIR__ . '/../autoload.php'; if (!class_exists('Symfony\\Component\\EventDispatcher\\EventDispatcher')) { \Demo::error('Please install "symfony/event-dispatcher" for run this demo (Notification with EventDispatcher).'); } use Symfony\Component\EventDispatcher\EventDispatcher; use Apple\ApnPush\Notification\Notification; use Apple\ApnPush\Notification\NotificationEvents; use Apple\ApnPush\Notification\SendException; use Apple\ApnPush\Notification\Connection; // Create event dispatcher $eventDispatcher = new EventDispatcher(); // Add complete listener $eventDispatcher->addListener(NotificationEvents::SEND_MESSAGE_ERROR, function () { print "[*] Error with send message.\n"; }); // Add error listener $eventDispatcher->addListener(NotificationEvents::SEND_MESSAGE_COMPLETE, function () { print "[-] Complete send message.\n"; }); // Create connection $connection = new Connection(CERTIFICATE_FILE, PASS_PHRASE, SANDBOX_MODE); // Create notification $notification = new Notification($connection); // Set event dispatcher $notification->setEventDispatcher($eventDispatcher); // Send correct message $notification->sendMessage(DEVICE_TOKEN, '[Correct] Hello'); try { // Send incorrect message