Skip to content

Commit

Permalink
Merge pull request #29 from tschoffelen/master
Browse files Browse the repository at this point in the history
Added support for iOS 8 Action categories
  • Loading branch information
ZhukV committed Aug 19, 2015
2 parents a69dc88 + 543ca91 commit 6b166e0
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 2 deletions.
52 changes: 50 additions & 2 deletions src/Apple/ApnPush/Notification/ApsData.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ class ApsData implements ApsDataInterface, \Serializable
*/
protected $sound;

/**
* @var string
*/
protected $category;

/**
* @var integer
*/
Expand Down Expand Up @@ -94,6 +99,43 @@ public function getBody()
return $this->body;
}

/**
* Set category for iOS 8 notification actions
*
* @param string $category
*
* @return ApsData
*
* @throws \InvalidArgumentException
*/
public function setCategory($category)
{
if (is_object($category)) {
$category = (string) $category;
}

if ($category !== null && !is_scalar($category)) {
throw new \InvalidArgumentException(sprintf(
'Category must be string, "%s" given.',
gettype($category)
));
}

$this->category = $category;

return $this;
}

/**
* Get category
*
* @return string
*/
public function getCategory()
{
return $this->category;
}

/**
* Set body localize
*
Expand Down Expand Up @@ -280,6 +322,10 @@ public function getPayloadData()
$apsData['badge'] = $this->badge;
}

if (null !== $this->category) {
$apsData['category'] = $this->category;
}

if (true === $this->contentAvailable) {
$apsData['content-available'] = 1;
}
Expand All @@ -298,7 +344,8 @@ public function serialize()
'body' => $this->body,
'body_custom' => $this->bodyCustom,
'sound' => $this->sound,
'badge' => $this->badge
'badge' => $this->badge,
'category' => $this->category
);

if (true === $this->contentAvailable) {
Expand All @@ -321,7 +368,8 @@ public function unserialize($data)
->setBody($data['body'])
->setBodyCustom($data['body_custom'])
->setSound($data['sound'])
->setBadge($data['badge']);
->setBadge($data['badge'])
->setCategory($data['category']);

if (isset($data['content-available'])) {
$this->setContentAvailable($data['content-available']);
Expand Down
14 changes: 14 additions & 0 deletions src/Apple/ApnPush/Notification/ApsDataInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,20 @@ public function setBody($body);
*/
public function getBody();

/**
* Set category for iOS 8 notification actions
*
* @param string $category
*/
public function setCategory($category);

/**
* Get category
*
* @return mixed
*/
public function getCategory();

/**
* Set body localize
*
Expand Down
24 changes: 24 additions & 0 deletions src/Apple/ApnPush/Notification/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,30 @@ public function getBody()
return $this->apsData->getBody();
}

/**
* Set category
*
* @param string $category
*
* @return Message
*/
public function setCategory($category)
{
$this->apsData->setCategory($category);

return $this;
}

/**
* Get category
*
* @return string
*/
public function getCategory()
{
return $this->apsData->getCategory();
}

/**
* Set body localize
*
Expand Down
14 changes: 14 additions & 0 deletions src/Apple/ApnPush/Notification/MessageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,20 @@ public function setBodyLocalize($localizeKey, array $params = array());
*/
public function getBody();

/**
* Set category
*
* @param string $category
*/
public function setCategory($category);

/**
* Get category
*
* @return string
*/
public function getCategory();

/**
* Set APS data
*
Expand Down

0 comments on commit 6b166e0

Please sign in to comment.