PHP code example of albaraam / yii2-gcm-apns

1. Go to this page and download the library: Download albaraam/yii2-gcm-apns library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

albaraam / yii2-gcm-apns example snippets


'components' => [
    'gcmApns' => [
        'class' => 'albaraam\yii2_gcm_apns\GcmApns',
        'google_api_key'=>'your_google_api_key',
        'environment'=>\albaraam\yii2_gcm_apns\GcmApns::ENVIRONMENT_SANDBOX,
        'pem_file'=>'path/to/pem/file'
    ],
]

// Message creation through the message builder.
$message = Yii::$app()->gcmApns->messageBuilder("Title","Body");

// Common attributes for both ios and android
$message
	->setTitle("Title")
	->setBody("Body")
	->setSound("sound.mp3")
	->setData(['foo'=>'bar']);

// Android specific attributes
$message->android
	->setTo("ids")
	->setIcon("icon")
	->setCollapseKey("collapse_key")
	->setColor("#333");

// IOS specific attributes
$message->ios
	->setTo("ids")
	->setSound("sound_ios.mp3") // custom sound for ios
	->setBadge(3);

// Send message
Yii::$app->gcmApns->send($message);