PHP Classes
elePHPant
Icontem

notymo: Send push notifications to iOS and Android devices

Recommend this page to a friend!
  Info   View files Documentation   View files View files (32)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2017-06-29 (1 year ago) RSS 2.0 feedNot enough user ratingsTotal: 205 All time: 8,150 This week: 305Up
Version License PHP version Categories
notymo 1.0.1The PHP License5PHP 5, Wireless and Mobile, Web services
Description Author

This package can send push notifications to iOS and Android devices.

It can configure a push notification and send it to a mobile device using Apple Push Notification service (APNs) or Google Cloud Messaging service (GCM).

The package can register callback functions that will be invoked after each relevant event type like the delivery of the message was completed, for each message that was sent or when an error happens.

Name: Edgar Asatryan <contact>
Classes: 4 packages by
Country: Armenia Armenia
Age: ???
All time rank: 30928 in Armenia Armenia
Week rank: 195 Up2 in Armenia Armenia Up
Innovation award
Innovation award
Nominee: 1x

Details

notymo Build Status Scrutinizer Code Quality Code Coverage

The notymo is a library which can help you to send push notifications on iOS and Andriod devices using single interface. The Library has no external dependencies.

Installation

The suggested installation method is via composer:

$ composer require nstdio/notymo: "dev-master"

or add

"nstdio/notymo": "dev-master"

to the require section of your composer.json file.

Usage

Single Interface

use nstdio\notymo\Message;
use nstdio\notymo\PushNotification;

$push = new PushNotification(array(
         // If you d?n't want to use one of the services we can just skip them loading.
         // It's obvious that the skipped service is not necessary to configure.
         // 'skipApns' => true,
         // 'skipGcm'  => true,
        'apns' => array(
            'live' => true, // We need to connect to APNS production server
            'cert' => 'live_cert.pem' // Also we must specify a SSL certificate for sending notification to iOS devices.
        ),
        'gcm'  => array(
            'apiKey' => 'api_key' // Google GCM Service API key. 
        ),
    )
);

/
 * If we have multiple recipients and all of them should receive same data we can create 
 * one single instance of Message class and send messages at once.
 */
$msg = Message::android();
$msg->setMessage("You have a notification.");
$msg->setSound("default");
$msg->setBadge(2);
$msg->setCustomData(array("user_data" => array()));
$msg->setToken(range(0, 10000));

/
 * Just clone original message and replace old device's tokens with new once for iOS devices.
 */
$msg2 = $msg->cloneWith(Message::TYPE_IOS, range(10000, 20000));

$push->enqueue($msg);
$push->enqueue($msg2); // Adding messages to queue

$push->send(); // Send notifications.

iOS

use nstdio\notymo\APNSNotification;
use nstdio\notymo\Message;

$apns = new APNSNotification(true, 'live_cert.pem');

$msg = Message::ios();
$msg->setMessage("This notification sent by cron.");
$msg->setSound("bang_bang");
$msg->setCustomData(array("segue" => "toSignInView"));
$msg->setToken(range(0, 10000)); //

$apns->enqueue($msg); // Adding messages to queue

$apns->send(); // Send notifications.

Android

use nstdio\notymo\GCMNotification;
use nstdio\notymo\Message;

$gcm = new GCMNotification("gcm_api_key");

$msg = Message::ios();
// ... same story as in iOS example.
$msg->setToken(range('A', 'Z'));

$gcm->enqueue($msg);

$gcm->send();

Applying lifecycle callbacks

LifeCycleCallback

| Method | Comment | Callback signature | | -------------| ------- | ------------------ | | void onComplete(Closure $callback) | Will be called when all messages are sent. | void function(MessageQueue $messages) | | void onEachSent(Closure $callback) | Will be called when the every message was sent. | void function(MessageInterface $message, array $response) | | void onError(Closure $callback) | Will be called when error occurs. Note that when error occured and this callback is not defined, an exception will be thrown. | void function(MessageInterface $message, PushNotificationException $exc) | | void detach() | This method has no Closure argument because it is not involved in the message sending lifecycle. The single assignment of this method to remove callbacks. Will be called immediately after onSent.| - |

// ...

$push->onComplete(function(MessageQueue $queue) {
    / @var MessageInterface $message */
    foreach ($queue as $message) {
        printf("Message %s not sent\n", $message->getToken())
    }
});

$push->onSent(function(MessageInterface $message, $response) use ($model) {
    $model->save(array(
        'device_token' => $message->getToken(),
        'is_sent' => $response['success'],
    ));
});

$push->onError(function(MessageInterface $message, PushNotificationException $e) {
    printf("Error %s occurs while sending %s\n", $message->getToken(), $e->getMessage());
});

$push->send();
  Files folder image Files  
File Role Description
Files folder imagesrc (13 files, 1 directory)
Files folder imagetests (1 file, 1 directory)
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file phpunit.xml.dist Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  src  
File Role Description
Files folder imageexception (4 files)
  Plain text file AbstractNotification.php Class Class source
  Plain text file APNSNotification.php Class Class source
  Plain text file CallbackInvoker.php Class Class source
  Plain text file Connection.php Class Class source
  Plain text file CurlWrapper.php Class Class source
  Plain text file GCMNotification.php Class Class source
  Plain text file LifeCycleCallback.php Class Class source
  Plain text file LifeCycleCallbackInvoker.php Class Class source
  Plain text file Message.php Class Class source
  Plain text file MessageInterface.php Class Class source
  Plain text file MessageQueue.php Class Class source
  Plain text file PushNotification.php Class Class source
  Plain text file PushNotificationInterface.php Class Class source

  Files folder image Files  /  src  /  exception  
File Role Description
  Plain text file ConnectionException.php Class Class source
  Plain text file InvalidCertException.php Class Class source
  Plain text file PushNotificationException.php Class Class source
  Plain text file UnsupportedNotificationTypeException.php Class Class source

  Files folder image Files  /  tests  
File Role Description
Files folder imagenotymo (9 files)
  Accessible without login Plain text file cacert.pem Data Auxiliary data

  Files folder image Files  /  tests  /  notymo  
File Role Description
  Plain text file AbstractNotificationTest.php Class Class source
  Plain text file APNSNotificationTest.php Class Class source
  Accessible without login Plain text file bootstrap.php Aux. Auxiliary script
  Plain text file CallbackInvokerTest.php Class Class source
  Plain text file GCMNotificationTest.php Class Class source
  Plain text file MessageQueueTest.php Class Class source
  Plain text file MessageTest.php Class Class source
  Plain text file PushNotificationTest.php Class Class source
  Plain text file TestCase.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:205
This week:0
All time:8,150
This week:305Up