spitalia/push-notification-gcm

PushNotificationGCM is small PHP library for send push notification to Android and iOS mobile devices.

dev-master 2015-07-16 11:04 UTC

This package is not auto-updated.

Last update: 2024-12-07 18:24:27 UTC


README

Google GCM Push Notification is small PHP library for send push notification to Android and iOS mobile devices.

Install

Please follow the guide Google GCM for configure the API Key.

Composer

The preferred way to install Push Notification GCM is via composer.

Add in your composer.json:

"require": {
	...
	"spitalia/push-notification-gcm": "dev-master"
	
}

then update your dependencies with composer update.

Start usage

    $pushNotificationGCM = new PushNotificationGCM($google_api_key);
    $devices = array($devicetoken);
    $message = ['data' => ['message' => 'hello', 'reason' => 'new_event']];
    
    try {
        foreach($devices as $devicetoken){
            $pushNotificationGCM->addDevice($devicetoken);
        }
        // set this for send silent push notification
        $pushNotificationGCM->silent_notification = true;
        
        // set the title of badge
        $pushNotificationGCM->default_title_notification = APP_TITLE;
        
        // set this for set verbose the variable $pushNotificationGCM->reponseGCM
        $pushNotificationGCM->debug = true;
        
        $pushNotificationGCM->addMessage($message);
        $pushNotificationGCM->push();
        
        
        // The array $pushNotificationGCM->reponseGCM contains array('success'=>array(),'failure'=>array()); if debug is true return other keys
        
    }catch (PushNotificationGCMException $e){
        echo 'Error code: '.$e->getPushNotificationCode()." - ".$e->getMessage();
    } catch(Exception $e){
        echo $e->getMessage();
    }
    

Creators

Securproject.it Team

Licence

Free for commercial and non-commercial use (Apache License or GPL).