A Apple Push Notification Service bundle for Laravel
###Artisan
php artisan bundle:install simpleapns
###Manually
https://github.com/fabiorphp/laravel-simpleapns
Add the following code to your application/bundle.php file:
'simpleapns' => array('auto' => true),
Move the config/simpleapns.php to the application folder and add the following to your application/config/simpleapns.php file:
return array(
'local' => array(
'host' => 'gateway.sandbox.push.apple.com:2195',
'cert' => path('app').'certificates/dev.pem',
'pass' => 'OPTIONAL PASSPHRASE', // Used when generating the *.p12 file
),
'prod' => array(
'host' => 'gateway.push.apple.com:2195',
'cert' => path('app').'certificates/prod.pem',
'pass' => 'OPTIONAL PASSPHRASE', // Used when generating the *.p12 file
)
);
Instance:
$apns = SimpleApns::make();
//or
$apns = new SimpleApns;
Custom configuration:
$apns = SimpleApns::make(
array(
'host' => 'gateway.sandbox.push.apple.com:2195',
'cert' => 'yourcertificate.pem',
'pass' => 'OPTIONAL PASSPHRASE', // Used when generating the *.p12 file
)
);
Send a message:
try
{
$apns->send(
array(
'alert' => 'Alert!',
'badge' => '2',
'sound' => 'default' // Not required
),
'device_token' // xdigits
);
}
catch(SimpleApns\SocketException $e)
{
echo $e->getMessage();
}
catch(SimpleApns\ValidationException $e)
{
print_r($e->get());
}
Questions @fabiorphp