/** * Send Message * * @param ApnsMessage $message * @return MessageResponse */ public function send(ApnsMessage $message) { if (!$this->isConnected()) { throw new Exception\RuntimeException('You must first open the connection by calling open()'); } $ret = $this->write($message->getPayloadJson()); if ($ret === false) { throw new Exception\RuntimeException('Server is unavailable; please retry later'); } return new MessageResponse($this->read()); }
/** * @param ApnsMessage $message * @return MessageResponse * @throws Exception\RuntimeException */ public function send(ApnsMessage $message) { if (!$this->isConnected()) { $this->open($this->environment, $this->certificate, $this->passPhrase); } $ret = $this->write($message->getPayloadJson()); if ($ret === false) { throw new Exception\RuntimeException('Server is unavailable; please retry later'); } if ($ret === 0) { throw new Exception\RuntimeException('Server is unavailable; broken pipe or closed connection'); } return new MessageResponse($this->read()); }