Skip to content

Commit c7e5c81

Browse files
authored
Merge pull request #17 from CodeMonkeysRu/release/v0.5
Release/v0.5
2 parents c32e240 + 1b8e4f9 commit c7e5c81

3 files changed

Lines changed: 39 additions & 0 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ $message
2727
->setTtl(123)
2828
->setRestrictedPackageName("com.example.trololo")
2929
->setDryRun(true)
30+
->setPriority(GCM\MessageMessage::PRIORITY_HIGH)
3031
;
3132

3233
try {
@@ -132,6 +133,7 @@ $sender = new GCM\Sender("YOUR GOOGLE API KEY", false, "/path/to/cacert.crt");
132133

133134
ChangeLog
134135
----------------------
136+
* v0.5 - Added support for "priority" flag (https://github.com/CodeMonkeysRu/GCMMessage/pull/16)
135137
* v0.4 - Code cleanup, PHP5.5 support dropped
136138
* v0.3 - Content-available added (https://github.com/CodeMonkeysRu/GCMMessage/pull/11)
137139
* v0.2 - Notifications added

library/CodeMonkeysRu/GCM/Message.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
*/
99
class Message
1010
{
11+
const PRIORITY_NORMAL = 'normal';
12+
const PRIORITY_HIGH = 'high';
1113

1214
/**
1315
* A string array with the list of devices (registration IDs) receiving the message.
@@ -96,6 +98,21 @@ class Message
9698
*/
9799
private $contentAvailable = true;
98100

101+
/**
102+
* Sets the priority of the message. Valid values are "normal" and "high." On iOS, these
103+
* correspond to APNs priority 5 and 10. By default, messages are sent with normal
104+
* priority. Normal priority optimizes the client app's battery consumption, and should
105+
* be used unless immediate delivery is required. For messages with normal priority, the
106+
* app may receive the message with unspecified delay.
107+
* When a message is sent with high priority, it is sent immediately, and the app can wake
108+
* a sleeping device and open a network connection to your server.
109+
*
110+
* Optional.
111+
*
112+
* @var string
113+
*/
114+
private $priority = self::PRIORITY_NORMAL;
115+
99116
/**
100117
* Allows developers to test their request without actually sending a message.
101118
*
@@ -222,4 +239,23 @@ public function setContentAvailable($contentAvailable)
222239
$this->contentAvailable = $contentAvailable;
223240
return $this;
224241
}
242+
243+
public function getPriority()
244+
{
245+
return $this->priority;
246+
}
247+
248+
public function setPriority($priority)
249+
{
250+
$allowedPriorities = array(self::PRIORITY_HIGH, self::PRIORITY_NORMAL);
251+
252+
if (!in_array($priority, $allowedPriorities, true)) {
253+
throw new \InvalidArgumentException(
254+
'Invalid priority "' . $priority . '", allowed are only these: ' . implode(', ', $allowedPriorities)
255+
);
256+
}
257+
258+
$this->priority = $priority;
259+
return $this;
260+
}
225261
}

library/CodeMonkeysRu/GCM/Sender.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ private function formMessageData(Message $message)
156156
'restricted_package_name' => 'getRestrictedPackageName',
157157
'dry_run' => 'getDryRun',
158158
'content_available' => 'getContentAvailable',
159+
'priority' => 'getPriority',
159160
);
160161

161162
foreach ($dataFields as $fieldName => $getter) {

0 commit comments

Comments
 (0)