public function testCustomDataAddedOK() { $expected = array("aps" => array(), "custom" => array("foo" => "bar")); $msg = new iOSMessage(); $msg->setData(array("custom" => array("foo" => "bar"))); $this->assertEquals($expected, $msg->getMessageBody()); }
/** * Funcion que envia un mensaje con el sevricio APN de Apple * @param $mes * @param $to */ private function sendAPNMessage($mes, $to, $wakeUp = true) { $message = new iOSMessage(); try { $message->setData($mes); } catch (\InvalidArgumentException $e) { throw $e; } $alert = []; $logger = $this->_container->get('logger'); $logger->emerg(implode(',', $mes)); $em = $this->_container->get("doctrine.orm.entity_manager"); $reDevice = $em->getRepository('ApplicationSopinetUserBundle:User'); /** @var User $user */ $user = $reDevice->findOneByPhone($mes['phone']); if ($user != null && $wakeUp) { if ($mes['chattype'] == 'event') { $em = $this->_container->get("doctrine.orm.entity_manager"); $reChat = $em->getRepository('PetyCashAppBundle:Chat'); $chat = $reChat->find($mes['chatid']); $text = $chat->getName() . '@' . $user->getUserName(); } else { $text = $user->getUserName(); } $alert['loc-args'] = array($text, $mes['text']); $alert['loc-key'] = $mes['type']; $message->setMessage($alert); $message->setAPSSound('default'); } $message->setDeviceIdentifier($to); $message->setAPSContentAvailable($wakeUp); $this->_container->get('rms_push_notifications')->send($message); }