diff --git a/README.md b/README.md index f4f4f28..b8b74ca 100644 --- a/README.md +++ b/README.md @@ -98,6 +98,7 @@ class AccountApproved extends Notification - `web()`: Sets the platform value to web. - `link()`: Accepts a string value which will lead to URI specified on notification click. - `title('')`: Accepts a string value for the title. +- `subtitle('')`: Accepts a string value for the subtitle (iOS). - `body('')`: Accepts a string value for the body. - `sound('')`: Accepts a string value for the notification sound file. Notice that if you leave blank the default sound value will be `default`. - `meta([...])`: Accepts an array of custom data to be sent along with the push message. Works for both platforms. See more at [Pusher Beams - Adding metadata to a notification](https://pusher.com/docs/beams/guides/publishing-to-multiple-devices) diff --git a/src/PusherMessage.php b/src/PusherMessage.php index 5fff2ae..d0e22aa 100644 --- a/src/PusherMessage.php +++ b/src/PusherMessage.php @@ -17,6 +17,11 @@ class PusherMessage */ protected string|null $title = null; + /** + * The message subtitle (iOS only). + */ + protected string|null $subtitle = null; + /** * The phone number the message should be sent from. */ @@ -202,6 +207,19 @@ public function title(string $value): self return $this; } + /** + * Set the message subtitle (iOS only). + * + * @param string $value + * @return $this + */ + public function subtitle(string $value): self + { + $this->subtitle = $value; + + return $this; + } + /** * Set the message body. * @@ -327,6 +345,10 @@ public function toiOS(): array ], ]; + if ($this->subtitle) { + $message['apns']['aps']['alert']['subtitle'] = $this->subtitle; + } + if ($this->meta && count($this->meta)) { $message['apns']['data'] = $this->meta; } diff --git a/tests/MessageTest.php b/tests/MessageTest.php index 6fcc51d..b983391 100644 --- a/tests/MessageTest.php +++ b/tests/MessageTest.php @@ -72,6 +72,14 @@ public function it_can_set_the_title(): void $this->assertEquals('myTitle', Arr::get($this->message->toAndroid(), 'fcm.notification.title')); } + /** @test */ + public function it_can_set_the_subtitle(): void + { + $this->message->subtitle('mySubTitle'); + + $this->assertEquals('mySubTitle', Arr::get($this->message->toiOS(), 'apns.aps.alert.subtitle')); + } + /** @test */ public function it_can_set_the_body(): void {