Beispiel #1
0
 /**
  * Fetch APNS Messages
  *
  * This gets called automatically by _pushMessage.  This will check with APNS for any invalid tokens and disable them from receiving further notifications.
  *
  * @param sting $development Which SSL to connect to, Sandbox or Production
  * @access private
  */
 private function _checkFeedback()
 {
     $ctx = stream_context_create();
     stream_context_set_option($ctx, 'ssl', 'local_cert', $this->__certificate);
     stream_context_set_option($ctx, 'ssl', 'verify_peer', false);
     $feedback_url = $this->isProduction() ? $this->__feedback_url : $this->__feedback_development_url;
     $fp = stream_socket_client($feedback_url, $error, $errorString, 60, STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT, $ctx);
     if (!$fp) {
         throw new Exception('Unable to connect to get feedback from Apple');
     }
     while ($devcon = fread($fp, 38)) {
         $arr = unpack("H*", $devcon);
         $rawhex = trim(implode("", $arr));
         $token = substr($rawhex, 12, 64);
         if (!empty($token)) {
             $device = new Push_Model_Iphone_Device();
             $device->findByToken($token);
             if ($device->getId()) {
                 $device->unregister();
             }
         }
     }
     fclose($fp);
 }