diff --git a/src/Services/AbstractPushService.php b/src/Services/AbstractPushService.php index a5e8ec3..6f698e1 100644 --- a/src/Services/AbstractPushService.php +++ b/src/Services/AbstractPushService.php @@ -9,6 +9,12 @@ abstract class AbstractPushService implements PushService */ protected $messageText = null; + /** + * @var string|null + * The text of the message + */ + protected $messageTitle = null; + /** * @var array|null * The data of the message diff --git a/src/Services/ApplePushService.php b/src/Services/ApplePushService.php index 2b65764..1ab3e79 100644 --- a/src/Services/ApplePushService.php +++ b/src/Services/ApplePushService.php @@ -13,6 +13,11 @@ class ApplePushService extends AbstractPushService */ private $client; + public function setMessageTitle($title) + { + throw new RuntimeException('APNS does not support message title'); + } + /** * @inheritdoc */ diff --git a/src/Services/GooglePushService.php b/src/Services/GooglePushService.php index b4614de..a7a715e 100644 --- a/src/Services/GooglePushService.php +++ b/src/Services/GooglePushService.php @@ -35,6 +35,17 @@ public function loadConfiguration($config) return true; } + /** + * Set message title + * + * @param string $title message title + */ + public function setMessageTitle($title) + { + $this->messageTitle = $title; + return $this; + } + /** * @inheritdoc */ @@ -48,8 +59,12 @@ public function send() $body['data'] = $this->messageData; } + if ($this->messageTitle !== null) { + $body['data']['title'] = $this->messageTitle; + } + if ($this->messageText !== null) { - $body['data']['message'] = $this->messageText; + $body['data']['content'] = $this->messageText; } $ok = []; diff --git a/src/Services/PushService.php b/src/Services/PushService.php index f543e36..3954a59 100644 --- a/src/Services/PushService.php +++ b/src/Services/PushService.php @@ -23,6 +23,16 @@ public function loadConfiguration($config); */ public function setMessageText($message); + /** + * Set the message title for this push message. + * + * @param string $title + * The message title to set + * @return self + * This instance, to allow chaining + */ + public function setMessageTitle($title); + /** * Set the message data for this push message. * This will clear any previous message data