Ejemplo n.º 1
0
 /**
  * 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;
 }
Ejemplo n.º 2
0
 /**
  * Get service message from origin.
  *
  * @param array $tokens Tokens
  * @param BaseOptionedModel|\Sly\NotificationPusher\Model\MessageInterface $message Message
  *
  * @return \ZendService\Google\Gcm\Message
  */
 public function getServiceMessageFromOrigin(array $tokens, BaseOptionedModel $message)
 {
     $data = $message->getOptions();
     $data['message'] = $message->getText();
     $serviceMessage = new ServiceMessage();
     $serviceMessage->setRegistrationIds($tokens);
     $serviceMessage->setData($data);
     $serviceMessage->setCollapseKey($this->getParameter('collapseKey'));
     $serviceMessage->setRestrictedPackageName($this->getParameter('restrictedPackageName'));
     $serviceMessage->setDelayWhileIdle($this->getParameter('delayWhileIdle', false));
     $serviceMessage->setTimeToLive($this->getParameter('ttl', 600));
     $serviceMessage->setDryRun($this->getParameter('dryRun', false));
     return $serviceMessage;
 }