develandoo/yii2-push-notification

Yii2 apns/gcm push notification

Installs: 26 725

Dependents: 2

Suggesters: 0

Security: 0

Stars: 36

Watchers: 13

Forks: 6

Open Issues: 2

Type:yii2-extension

1.1.1 2018-02-16 14:25 UTC

This package is not auto-updated.

Last update: 2024-04-13 17:57:24 UTC


README

INSTALLATION

Run

composer require develandoo/yii2-push-notification

or add

 "develandoo/yii2-push-notification": "^1.0"

CONFIGURATION

in your main.php your configuration would look like this

    'components' => [
         'push' => [
             'class' => 'develandoo\notification\Push',
             'options' => [
                 'returnInvalidTokens' => true //default false
             ],
             'apnsConfig' => [
                 'environment' => Push::APNS_ENVIRONMENT_PRODUCTION or Push::APNS_ENVIRONMENT_SANDBOX,
                 'pem' => 'PEM_FILE_ABS_URL',
                 'passphrase' => 'YOUR_PASS_PHRASE', //optional
             ],
             'gcmConfig' => [
                 'apiAccessKey' => 'YOUR_GCM_API_KEY'
             ]
         ]
     ]

EXAMPLE

$push = Yii::$app->push;

// ios signle token example
$push->ios()->send('token', [
    'custom-key' => 'custom-value',
    'aps' => [
        'alert' => [
            'loc-key' => 'i18n_key',
            'loc-args' => ['arg1'],
        ]
    ],
    'badge' => 1,
    'sound' => 'default'
]);

// ios multiple tokens example
$push->ios()->send(['token1,token2'], [
    'custom-key' => 'custom-value',
    'aps' => [
        'alert' => 'STRING_MESSAGE'
    ],
    'badge' => 1,
    'sound' => 'default'
]);

// android example
$push->android()->send(['token1,token2'], [
    'key' => 'i18n_key',
    'args' => ['arg1'],
    'custom-key'=>'custom-value'
]);

// mixed tokens example
$push->send([
    'ios-tokens1',
    'android-token1',
    'android-token2',
    'ios-token2'
], $payload);

// firebase (both ios and android are supported) multiple tokens example
$push->firebase()->send(['token1','token2'], [
    // Background (closed) application data.
    'notification' => [
        'body' => 'Background application message',
        'title' => 'AppName',
        'sound' => 'default',
    ],
    // Foreground (running) application data.
    'data' => [
        'custom-key' => 'Any custom data could be delivered into foreground application. '
        . 'In order to simulate push notification, this data should be used inside "local notification" by client application.',
    ],
]);

EXCEPTION CASES

  • Apns environment is invalid.
  • Apns pem is invalid.
  • Gcm api access key is invalid.
  • Gcm in not enabled.
  • Apns in not enabled.

© DEVELANDOO 2017