-
Notifications
You must be signed in to change notification settings - Fork 0
/
testPushIOS.php
executable file
·75 lines (64 loc) · 2.38 KB
/
testPushIOS.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
require_once './vendor/autoload.php';
use Sly\NotificationPusher\PushManager,
Sly\NotificationPusher\Adapter\Apns as ApnsAdapter,
Sly\NotificationPusher\Collection\DeviceCollection,
Sly\NotificationPusher\Model\Device,
Sly\NotificationPusher\Model\Message,
Sly\NotificationPusher\Model\Push;
// First, instantiate the manager.
//
// Example for production environment:
$pushManager = new PushManager(PushManager::ENVIRONMENT_PROD);
//
// Development one by default (without argument).
//$pushManager = new PushManager(PushManager::ENVIRONMENT_DEV);
// Then declare an adapter.
$apnsAdapter = new ApnsAdapter(array(
'certificate' => __DIR__.'/apple_push_notification_production.pem',
'passPhrase' => 'passp01+'
));
// Set the device(s) to push the notification to.
$devices = new DeviceCollection(array(
new Device('f4c13321c34816430fccbb94b370b7c8bcab6c4272fe91dffd5c40335e3b725a', array('badge' => 5)),
// new Device('Token2', array('badge' => 1)),
// new Device('Token3'),
));
// Then, create the push skel.
$message = new Message('This is an example.', array(
'badge' => 1,
// 'sound' => 'example.aiff',
//
// 'actionLocKey' => 'Action button title!',
// 'locKey' => 'localized key',
// 'locArgs' => array(
// 'localized args',
// 'localized args',
// 'localized args'
// ),
// 'launchImage' => 'image.jpg',
//
// 'custom' => array(
// 'custom data' => array(
// 'we' => 'want',
// 'send to app'
// )
// )
));
// Finally, create and add the push to the manager, and push it!
$push = new Push($apnsAdapter, $devices, $message);
$pushManager->add($push);
$pushResult = $pushManager->push(); // Returns a collection of notified devices
echo "\n".'$pushResult: ';
/** @var \Sly\NotificationPusher\Model\Push $notifiedDevice */
foreach ($pushResult as $notifiedDevice) {
/** @var \ZendService\Apple\Apns\Response\Message $responseMessage */
$responseMessage = $notifiedDevice->getAdapter()->getResponse();
echo "\n".'-- status: '.$notifiedDevice->getStatus()
.'; isPushed: '.$notifiedDevice->isPushed()
.'; message: '.($notifiedDevice->getMessage() ? $notifiedDevice->getMessage()->getText() : '')
.'; response: '.$responseMessage->getCode().' - '.$responseMessage->getId();
}
echo "\n";