Skip to content

Commit

Permalink
Merge pull request #91 from angvp/feature/voip-tokens
Browse files Browse the repository at this point in the history
Add support for different push notification types
  • Loading branch information
edamov committed Nov 20, 2019
2 parents dffde74 + a04d619 commit 9404502
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
30 changes: 30 additions & 0 deletions src/Payload.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,15 @@ class Payload implements \JsonSerializable
*/
private $customValues;

/**
* Push notification type
*
* https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/sending_notification_requests_to_apns#2947607
*
* @var string
*/
private $pushType;

protected function __construct()
{
}
Expand Down Expand Up @@ -322,6 +331,27 @@ public function getCustomValue($key)
return $this->customValues[$key];
}

/**
* Set push type for Payload.
*
* @param string $pushType
* @return Payload
*/
public function setPushType($pushType) {
$this->pushType = $pushType;

return $this;
}

/**
* Get push type for Payload.
*
* @return string
*/
public function getPushType() {
return $this->pushType;
}

/**
* Convert Payload to JSON.
*
Expand Down
13 changes: 7 additions & 6 deletions src/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,14 @@ private function prepareApnsHeaders(Notification $notification)
if (!empty($notification->getCollapseId())) {
$this->headers[self::HEADER_APNS_COLLAPSE_ID ] = $notification->getCollapseId();
}

// new header required to support iOS 13

$this->headers[self::HEADER_APNS_PUSH_TYPE] = 'alert';

if ($notification->getPayload()->isContentAvailable()) {
// if the push type was set when the payload was created then it will set that as a push type,
// otherwise we would do our best in order to guess what push type is.
if (!empty($notification->getPayload()->getPushType())) {
$this->headers[self::HEADER_APNS_PUSH_TYPE] = $notification->getPayload()->getPushType();
} else if ($notification->getPayload()->isContentAvailable()) {
$this->headers[self::HEADER_APNS_PUSH_TYPE] = 'background';
} else {
$this->headers[self::HEADER_APNS_PUSH_TYPE] = 'alert';
}
}
}

0 comments on commit 9404502

Please sign in to comment.