Beispiel #1
0
 /**
  * Add a new device.
  *
  * @param string|Device $device
  */
 public function addDevice($device)
 {
     if (!$device instanceof Device) {
         $device = new Device($device);
     }
     $token = $device->getToken();
     if (!$this->isValidToken($token)) {
         throw new AdapterException('Adapter "' . get_class($this) . '" does not support device token "' . $token . '" .');
     }
     $this->devices[$device->getToken()] = $device;
 }
Beispiel #2
0
 /**
  * Get zend apns message.
  *
  * @param Device $device
  * @param mixed $message
  * @return ZendMessage
  */
 protected function getZendMessage(Device $device, $message)
 {
     $message = $this->getMessage($message);
     $options = new Options(array_merge($message->getOptions(), $device->getOptions()));
     // apns identifier
     $zendMessage = new ZendMessage();
     $zendMessage->setId(time());
     // apns alert options
     $zendMessage->setAlert(new ZendMessageAlert($message->getText(), $options->getOption('actionLocKey'), $options->getOption('locKey'), $options->getOption('locArgs'), $options->getOption('launchImage')));
     // apns badge number
     $badge = intval($device->getOption('badge')) + intval($message->getOption('badge'));
     $zendMessage->setBadge($badge);
     // others...
     $zendMessage->setToken($device->getToken());
     $zendMessage->setSound($options->getOption('sound', 'bingbong.aiff'));
     $zendMessage->setCustom($options->getOption('custom', []));
     return $zendMessage;
 }