Example #1
0
 /**
  * Send payload data to apple apns server
  *
  * @param MessageInterface $message
  *
  * @return bool
  *
  * @throws SendException
  */
 private function sendPayload(MessageInterface $message)
 {
     $payload = $this->payloadFactory->createPayload($message);
     $response = $this->writePayload($payload);
     if ($this->checkForErrors && $this->connection->isReadyRead()) {
         $responseApn = $this->connection->read(6);
         if (!$responseApn && $this->recreateConnection) {
             // Not read data from apn server. Close connection?
             if ($this->logger) {
                 $this->logger->debug('APN server returned empty data. Close connection? Try recreate connection...');
             }
             // Try recreate connection
             $this->connection->close();
             $this->connection->connect();
             $response = $this->writePayload($payload);
             if ($this->connection->isReadyRead()) {
                 $responseApn = $this->connection->read(6);
             } else {
                 return $response;
             }
         }
         $error = SendException::parseFromAppleResponse($responseApn, $message);
         throw $error;
     }
     return $response;
 }