Skip to content

Commit

Permalink
Merge pull request #20 from VasylDmytruk/apns
Browse files Browse the repository at this point in the history
Added priority property.
  • Loading branch information
VasylDmytruk authored May 7, 2020
2 parents b86bf63 + 19b8afe commit 15fbb1b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
],
"minimum-stability": "dev",
"require": {
"php": ">=5.5.0"
"php": ">=5.5.0",
"ext-curl": "*",
"ext-json": "*"
},
"require-dev": {
"symfony/var-dumper": "*"
Expand Down
16 changes: 16 additions & 0 deletions src/AppleNotificationServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@ class AppleNotificationServer
const CURL_HTTP_VERSION_2_0_KEY = 'CURL_HTTP_VERSION_2_0';
const CURL_HTTP_VERSION_2_0_VALUE = 3;
const APN_TOPIC_HEADER = 'apns-topic';

const APN_EXPIRATION_HEADER = 'apns-expiration';
const APN_PUSH_TYPE_HEADER = 'apns-push-type';
const APN_PRIORITY_HEADER = 'apns-priority';

const PRIORITY_HIGH = 10; // default
const PRIORITY_NORMAL = 5;

const PUSH_TYPE_ALERT = 'alert';
const PUSH_TYPE_BACKGROUND = 'background';
Expand Down Expand Up @@ -69,6 +74,11 @@ class AppleNotificationServer
* @see https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/sending_notification_requests_to_apns
*/
protected $pushType;
/**
* @var int 'apns-priority' header value. If not set APNS treats it's value as 10 (HIGH).
* @see https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/sending_notification_requests_to_apns
*/
protected $priority;


/**
Expand Down Expand Up @@ -245,11 +255,13 @@ protected function setHeaders(array &$curlOptions)
$this->setHeader($curlOptions, self::APN_TOPIC_HEADER, $this->topic);
$this->setHeader($curlOptions, self::APN_EXPIRATION_HEADER, $this->expiration);
$this->setHeader($curlOptions, self::APN_PUSH_TYPE_HEADER, $this->pushType);
$this->setHeader($curlOptions, self::APN_PRIORITY_HEADER, $this->priority);
}

/**
* Sets curl header.
*
* @param array $curlOptions
* @param string $headerKey
* @param string $headerValue
*/
Expand Down Expand Up @@ -299,6 +311,10 @@ public function setPushType($pushType)
{
if (is_string($pushType)) {
$this->pushType = $pushType;

if ($pushType === self::PUSH_TYPE_BACKGROUND) {
$this->priority = self::PRIORITY_NORMAL;
}
}
}
}

0 comments on commit 15fbb1b

Please sign in to comment.