コード例 #1
0
ファイル: Notification.php プロジェクト: integer/AppleApnPush
 /**
  * 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;
 }
コード例 #2
0
ファイル: Feedback.php プロジェクト: sgmendez/AppleApnPush
 /**
  * Get invalid devices
  *
  * @return array|Device[]
  *
  * @throws Exception\ConnectionUndefinedException
  */
 public function getInvalidDevices()
 {
     if (!$this->connection) {
         throw new Exception\ConnectionUndefinedException();
     }
     if (!$this->connection->is()) {
         if ($this->logger) {
             $this->logger->debug('Create feedback connection...');
         }
         $this->connection->create();
     }
     $data = $this->connection->read(-1);
     $this->connection->close();
     $feedback = array();
     if ($data) {
         foreach (str_split($data, 38) as $deviceData) {
             $feedback[] = new Device($deviceData);
         }
     }
     if ($this->logger) {
         $this->logger->info(sprintf('%d device tokens received from feedback service.', count($feedback)));
     }
     return $feedback;
 }