Push Notification GCM
Google GCM Push Notification is small PHP library for send push notification to Android and iOS mobile devices., (*1)
Install
Please follow the guide Google GCM for configure the API Key., (*2)
Composer
The preferred way to install Push Notification GCM is via composer., (*3)
Add in your composer.json
:, (*4)
"require": {
...
"spitalia/push-notification-gcm": "dev-master"
}
then update your dependencies with composer update
., (*5)
Start usage
``` php, (*6)
$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();
}
```, (*7)
Creators
Securproject.it Team, (*8)
Licence
Free for commercial and non-commercial use (Apache License or GPL)., (*9)