The preferred method of installation is via Packagist and Composer. Run the following command to install the package and add it as a requirement to your project's composer.json
:
composer require abraovic/phpush
You can find more examples under examples section of this lib
<?php
require 'vendor/autoload.php';
use abraovic\PHPush;
use abraovic\PHPush\Exception\PHPushException;
try {
$type = PHPush\Push\Push::IOS;
$credentials = [
'device_token' => 'fake-token', // for multiple use an array 'device_token' => ['fake-token-1', 'fake-token-2', ...]
'certificate_path' => 'fake-cert',
'certificate_phrase' => '',
'dev' => true
];
// enable printing payload before send (for development purpose)
PHPush\Push\Push::$printPayload = true;
$push = new PHPush\Push\Push($type, $credentials);
$message = new PHPush\Push\Message($type, "Hello");
$message->setBadge(200);
$message->setBody('body');
$iosMsg = $message->getMessage();
$iosMsg->setSound('default');
if ($push->sendMessage($message)) {
echo "sent";
}
} catch (PHPushException $e) {
echo 'Caught exception: ' . $e->getMessage() . "\n";
}
Contributions are welcome! Please read CONTRIBUTING for details.
The abraovic/phpush library is copyright © Ante Braovic and licensed for use under the Apache2 License.