PHP code example of tecsvit / yii2-apns

1. Go to this page and download the library: Download tecsvit/yii2-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/ */

    

tecsvit / yii2-apns example snippets


'components' => [
    ...
    'apns' => [
        'class' => '\tecsvit\apns\src\Sender',
        'apnsHostProd'  => 'gateway.push.apple.com',
        'apnsHostTest'  => 'gateway.sandbox.push.apple.com',
        'apnsPort'      => 2195,
        'apnsCertProd'  => dirname(__DIR__) . '/path/to/prod-serc/apple_push_notification_production.pem',
        'apnsCertTest'  => dirname(__DIR__) . '/path/to/test-serc/apple_push_notification_test.pem',
        'apnsPassphrase'=> dirname(__DIR__) . '/path/to/passphare',
        'timeout'       => 500000, //microseconds,
        'mode'          => 'prod' //'prod', 'dev' or 'test', default 'dev'
    ],
    ...
]


/**
 * @param array $alert Example: ['alert' => 'Push Message'] 
 * @param string $token Apple token device
 * @param bool $closeAfterPush Close the connection after the push?
 */
Yii::$app->apns->send($alert, $token, $closeAfterPush); 

php composer.phar