Skip to content
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

add APNS command 2 support, for ios 8 #79

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
18 changes: 18 additions & 0 deletions ApnsPHP/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,24 @@ public function getSound()
return $this->_sSound;
}

/**
* Get notification priority
* @return int
*/
public function getPriority()
{
return $this->_nPriority;
}

/**
* Set notification priority
* @param int $nPriority
*/
public function setPriority($nPriority = 10)
{
$this->_nPriority = $nPriority;
}

/**
* Initiates the Newsstand background download.
* @see http://tinyurl.com/ApplePushNotificationNewsstand
Expand Down
20 changes: 12 additions & 8 deletions ApnsPHP/Push.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*/
class ApnsPHP_Push extends ApnsPHP_Abstract
{
const COMMAND_PUSH = 1; /**< @type integer Payload command. */
const COMMAND_PUSH = 2; /**< @type integer Payload command. */

const ERROR_RESPONSE_SIZE = 6; /**< @type integer Error-response packet size. */
const ERROR_RESPONSE_COMMAND = 8; /**< @type integer Error-response command code. */
Expand All @@ -49,6 +49,8 @@ class ApnsPHP_Push extends ApnsPHP_Abstract
6 => 'Invalid topic size',
7 => 'Invalid payload size',
8 => 'Invalid token',
10 => 'Shutdown',
255 => 'None (unknown)',
self::STATUS_CODE_INTERNAL_ERROR => 'Internal error'
); /**< @type array Error-response messages. */

Expand Down Expand Up @@ -104,7 +106,8 @@ public function add(ApnsPHP_Message $message)
$message->getRecipient($i),
$sMessagePayload,
$nMessageID,
$message->getExpiry()
$message->getExpiry(),
$message->getPriority()
),
'ERRORS' => array()
);
Expand Down Expand Up @@ -260,14 +263,15 @@ public function getErrors($bEmpty = true)
* the notification at all. Default is 86400 * 7, 7 days.
* @return @type string A binary notification.
*/
protected function _getBinaryNotification($sDeviceToken, $sPayload, $nMessageID = 0, $nExpire = 604800)
protected function _getBinaryNotification($sDeviceToken, $sPayload, $nMessageID = 0, $nExpire = 604800, $priority = 10)
{
$nTokenLength = strlen($sDeviceToken);
$nPayloadLength = strlen($sPayload);
$pn = pack('CnH*', 1, 32, $sDeviceToken)
. pack('CnA*', 2, strlen($sPayload), $sPayload)
. pack('CnN', 3, 4, $nMessageID)
. pack('CnN', 4, 4, $nExpire > 0 ? time() + $nExpire : 0)
. pack('CnC', 5, 1, $priority);

$sRet = pack('CNNnH*', self::COMMAND_PUSH, $nMessageID, $nExpire > 0 ? time() + $nExpire : 0, self::DEVICE_BINARY_SIZE, $sDeviceToken);
$sRet .= pack('n', $nPayloadLength);
$sRet .= $sPayload;
$sRet = pack('CN', self::COMMAND_PUSH, strlen($pn)) . $pn;

return $sRet;
}
Expand Down