diff --git a/library/CodeMonkeysRu/GCM/Message.php b/library/CodeMonkeysRu/GCM/Message.php index f116005..b929b5b 100644 --- a/library/CodeMonkeysRu/GCM/Message.php +++ b/library/CodeMonkeysRu/GCM/Message.php @@ -8,6 +8,8 @@ */ class Message { + const PRIORITY_NORMAL = 'normal'; + const PRIORITY_HIGH = 'high'; /** * A string array with the list of devices (registration IDs) receiving the message. @@ -96,6 +98,21 @@ class Message */ private $contentAvailable = true; + /** + * Sets the priority of the message. Valid values are "normal" and "high." On iOS, these + * correspond to APNs priority 5 and 10. By default, messages are sent with normal + * priority. Normal priority optimizes the client app's battery consumption, and should + * be used unless immediate delivery is required. For messages with normal priority, the + * app may receive the message with unspecified delay. + * When a message is sent with high priority, it is sent immediately, and the app can wake + * a sleeping device and open a network connection to your server. + * + * Optional. + * + * @var string + */ + private $priority = self::PRIORITY_NORMAL; + /** * Allows developers to test their request without actually sending a message. * @@ -222,4 +239,23 @@ public function setContentAvailable($contentAvailable) $this->contentAvailable = $contentAvailable; return $this; } + + public function getPriority() + { + return $this->priority; + } + + public function setPriority($priority) + { + $allowedPriorities = array(self::PRIORITY_HIGH, self::PRIORITY_NORMAL); + + if (!in_array($priority, $allowedPriorities, true)) { + throw new \InvalidArgumentException( + 'Invalid priority "' . $priority . '", allowed are only these: ' . implode(', ', $allowedPriorities) + ); + } + + $this->priority = $priority; + return $this; + } } diff --git a/library/CodeMonkeysRu/GCM/Sender.php b/library/CodeMonkeysRu/GCM/Sender.php index ac3e149..19a21f1 100644 --- a/library/CodeMonkeysRu/GCM/Sender.php +++ b/library/CodeMonkeysRu/GCM/Sender.php @@ -156,6 +156,7 @@ private function formMessageData(Message $message) 'restricted_package_name' => 'getRestrictedPackageName', 'dry_run' => 'getDryRun', 'content_available' => 'getContentAvailable', + 'priority' => 'getPriority', ); foreach ($dataFields as $fieldName => $getter) {