Exemple #1
0
 /**
  * Get Payload
  * Generate APN array.
  *
  * @return array
  */
 public function getPayload()
 {
     $message = array();
     $aps = array();
     if ($this->alert && ($alert = $this->alert->getPayload())) {
         $aps['alert'] = $alert;
     }
     if (!is_null($this->badge)) {
         $aps['badge'] = $this->badge;
     }
     if (!is_null($this->sound)) {
         $aps['sound'] = $this->sound;
     }
     if (!is_null($this->contentAvailable)) {
         $aps['content-available'] = $this->contentAvailable;
     }
     if (!is_null($this->category)) {
         $aps['category'] = $this->category;
     }
     if (!is_null($this->urlArgs)) {
         $aps['url-args'] = $this->urlArgs;
     }
     if (!empty($this->custom)) {
         $message = array_merge($this->custom, $message);
     }
     if (!empty($aps)) {
         $message['aps'] = $aps;
     }
     return $message;
 }
Exemple #2
0
 /**
  * Build a \ZendService\Apple\Apns\Message from a \HipsterJazzbo\Telegraph\Message
  *
  * @param \HipsterJazzbo\Telegraph\Pushable $pushable
  * @param \HipsterJazzbo\Telegraph\Message  $message
  *
  * @return \ZendService\Apple\Apns\Message
  */
 protected function buildServiceMessage(Pushable $pushable, Message $message)
 {
     $apnsMessage = new ApnsMessage();
     $apnsMessage->setId((string) Uuid::uuid4());
     $apnsMessage->setToken($pushable->getToken());
     $apnsMessage->setCustom($message->getData());
     if (!empty($message->getBody())) {
         $alert = new Alert();
         $alert->setTitle($message->getTitle());
         $alert->setBody($message->getBody());
         $apnsMessage->setAlert($alert);
     }
     if ($message->getBadge()) {
         $apnsMessage->setBadge($message->getBadge());
     }
     if ($message->isSilent()) {
         $apnsMessage->setContentAvailable(1);
     }
     return $apnsMessage;
 }
Exemple #3
0
 /**
  * Get Payload
  * Generate APN array.
  *
  * @return array
  */
 public function getPayload()
 {
     $message = array();
     $message['aps'] = array();
     if ($this->alert && ($alert = $this->alert->getPayload())) {
         $message['aps']['alert'] = $alert;
     }
     if (!is_null($this->badge)) {
         $message['aps']['badge'] = $this->badge;
     }
     if (!is_null($this->sound)) {
         $message['aps']['sound'] = $this->sound;
     }
     if (!empty($this->custom)) {
         $message = array_merge($this->custom, $message);
     }
     return $message;
 }
 /**
  * Get service message from origin.
  *
  * @param \Sly\NotificationPusher\Model\DeviceInterface $device Device
  * @param BaseOptionedModel|\Sly\NotificationPusher\Model\MessageInterface $message Message
  *
  * @return \ZendService\Apple\Apns\Message
  */
 public function getServiceMessageFromOrigin(DeviceInterface $device, BaseOptionedModel $message)
 {
     $badge = $message->hasOption('badge') ? (int) ($message->getOption('badge') + $device->getParameter('badge', 0)) : 0;
     $sound = $message->getOption('sound', 'bingbong.aiff');
     $contentAvailable = $message->getOption('content-available');
     $alert = new ServiceAlert($message->getText(), $message->getOption('actionLocKey'), $message->getOption('locKey'), $message->getOption('locArgs'), $message->getOption('launchImage'));
     if ($actionLocKey = $message->getOption('actionLocKey')) {
         $alert->setActionLocKey($actionLocKey);
     }
     if ($locKey = $message->getOption('locKey')) {
         $alert->setLocKey($locKey);
     }
     if ($locArgs = $message->getOption('locArgs')) {
         $alert->setLocArgs($locArgs);
     }
     if ($launchImage = $message->getOption('launchImage')) {
         $alert->setLaunchImage($launchImage);
     }
     $serviceMessage = new ServiceMessage();
     $serviceMessage->setId(sha1($device->getToken() . $message->getText()));
     $serviceMessage->setAlert($alert);
     $serviceMessage->setToken($device->getToken());
     $serviceMessage->setBadge($badge);
     $serviceMessage->setCustom($message->getOption('custom', array()));
     if (null !== $sound) {
         $serviceMessage->setSound($sound);
     }
     if (null !== $contentAvailable) {
         $serviceMessage->setContentAvailable($contentAvailable);
     }
     return $serviceMessage;
 }
 public function testAlertPayloadSendsOnlyBody()
 {
     $alert = new Alert('Foo wants Bar');
     $payload = $alert->getPayload();
     $this->assertEquals('Foo wants Bar', $payload);
 }