Example #1
0
 /**
  * @param $key
  * @param $token
  * @param $content
  *
  * @return \C2iS\ApnsSender\Model\Message
  */
 public static function createMessage($key, $token, $content)
 {
     $message = new Message();
     $message->setExpiry($expiry = time() + 90 * 24 * 60 * 60);
     $payload = pack("C", 1) . pack("N", $key) . pack("N", $expiry) . pack("n", 32);
     $payload .= pack('H*', str_replace(' ', '', $token)) . pack("n", strlen($content)) . $content;
     $message->setPayload($payload);
     $message->setToken($token);
     return $message;
 }
Example #2
0
 /**
  * @param Message $message
  *
  * @return bool
  */
 public function write(Message $message)
 {
     $attempt = 1;
     $content = $message->getPayload();
     $contentLength = strlen($content);
     try {
         while ((int) $this->stream->write($content) !== $contentLength && $attempt++ < self::RETRY) {
             Sleep::millisecond(self::RETRY_INTERVAL);
         }
         $success = $attempt < self::RETRY;
     } catch (\Exception $e) {
         $this->logger->warning('An error occurred writing to APNS stream', array('error_message' => $e->getMessage()));
         $success = false;
     }
     return $success;
 }