Skip to content

Ability to add subtitle for iOS push notification #77

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,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`.
- `icon('')`: Accepts a string value for the icon file. (Android Only)
Expand Down
22 changes: 22 additions & 0 deletions src/PusherMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ class PusherMessage
*/
protected string|null $title = null;

/**
* The message subtitle.
*/
protected string|null $subtitle = null;

/**
* The phone number the message should be sent from.
*/
Expand Down Expand Up @@ -195,6 +200,19 @@ public function title(string $value): self
return $this;
}

/**
* Set the message subtitle.
*
* @param string $value
* @return $this
*/
public function subtitle(string $value): self
{
$this->subtitle = $value;

return $this;
}

/**
* Set the message body.
*
Expand Down Expand Up @@ -306,6 +324,10 @@ public function toiOS(): array
],
];

if ($this->subtitle) {
$message['apns']['aps']['alert']['subtitle'] = $this->subtitle;
}

$this->formatMessage($message);

return $message;
Expand Down
8 changes: 8 additions & 0 deletions tests/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down