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()); }
/** * executeRms */ protected function executeRms() { $message = $this->input->getArgument('message'); $device = $this->input->getArgument('device'); $pushNotification = new iOSMessage(); $pushNotification->setMessage($message); $pushNotification->setDeviceIdentifier($device); $this->notifications->send($pushNotification); }
public function sendOneNotification($notification) { if ($notification->getPlayer() == null) { return; } if (strlen($notification->getPlayer()->getApplePushToken()) > 5) { //limit is 100 characters $message = new iOSMessage(); $message->setMessage($notification->getMessage()); $message->setAPSSound("default"); $message->setDeviceIdentifier(str_replace('%', '', $notification->getPlayer()->getApplePushToken())); $this->pushNotifications->send($message); $this->logger->info('Notifying player id: ' . $notification->getPlayer()->getId() . " message: " . $notification->getMessage(), get_defined_vars()); $notification->setSentOn(new \DateTime("now")); } }
/** * @param Notification $notification * @param string $deviceToken * * @return iOSMessage */ protected function createMessage(Notification $notification, $deviceToken) { $pushNotification = new iOSMessage(); $pushNotification->setMessage($notification->getMessage()); $pushNotification->setDeviceIdentifier($deviceToken['token']); $pushNotification->setAPSSound('default'); $pushNotification->setAPSBadge($deviceToken['badge']); /* @TODO send extra data to the client or not foreach ($notification->getContent() as $key => $value) { $pushNotification->addCustomData($key, $value); } */ return $pushNotification; }
protected function sendNotificationIfNecessary(Challenge $challenge) { //It is a new challenge if ($challenge->getState() == 0) { //If token present if (strlen($challenge->getChallengedPlayer()->getApplePushToken()) > 5) { //limit is 100 characters $message = new iOSMessage(); $maxNameLength = 30; $message->setMessage(substr($challenge->getChallengerPlayer()->getName(), 0, $maxNameLength) . (strlen($challenge->getChallengerPlayer()->getName()) > $maxNameLength ? '...' : '') . ' has challenged you to ' . ($challenge->getType() == 0 ? "collect more than " . $challenge->getValue() . " coins!" : "run further than " . $challenge->getValue() . " meters!")); $message->setAPSSound("default"); $message->setDeviceIdentifier(str_replace('%', '', $challenge->getChallengedPlayer()->getApplePushToken())); $this->container->get('rms_push_notifications')->send($message); $this->container->get('logger')->info('Notifying player id: ' . $challenge->getChallengedPlayer()->getId() . " that his friend id: " . $challenge->getChallengerPlayer()->getId() . " has started a new challenge id : " . $challenge->getId(), get_defined_vars()); } } else { if ($challenge->getState() == 2 || $challenge->getState() == 3) { //If token present if (strlen($challenge->getChallengerPlayer()->getApplePushToken()) > 5) { //limit is 100 characters $message = new iOSMessage(); $maxNameLength = 30; $challengedPlayerName = substr($challenge->getChallengedPlayer()->getName(), 0, $maxNameLength) . (strlen($challenge->getChallengedPlayer()->getName()) > $maxNameLength ? '...' : ''); $message->setMessage($challenge->getState() == 2 ? 'You have WON a challenge against ' . $challengedPlayerName . ". Claim your reward!" : 'You have LOST a challenge against ' . $challengedPlayerName . "."); $message->setAPSSound("default"); $message->setDeviceIdentifier(str_replace('%', '', $challenge->getChallengerPlayer()->getApplePushToken())); $this->container->get('rms_push_notifications')->send($message); $this->container->get('logger')->info('Notifying player id: ' . $challenge->getChallengerPlayer()->getId() . " that his friend id: " . $challenge->getChallengerPlayer()->getId() . " has " . ($challenge->getState() == 2 ? "lost" : "won") . " a challenge id : " . $challenge->getId(), get_defined_vars()); } } } }
/** * 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); }
private function checkIfBeatenHighscoreOfFriends(Player $player, $previousDistanceBest, $newDistanceBest) { foreach ($player->getFriends() as $friend) { if ($friend->getDistanceBest() >= $previousDistanceBest && $friend->getDistanceBest() < $newDistanceBest && strlen($friend->getApplePushToken()) > 0) { $message = new iOSMessage(); $maxNameLength = 30; $message->setMessage("Your friend " . substr($player->getName(), 0, $maxNameLength) . (strlen($player->getName()) > $maxNameLength ? '...' : '') . ' has beaten your high-score!'); $message->setAPSSound("default"); $message->setDeviceIdentifier(str_replace('%', '', $friend->getApplePushToken())); $this->container->get('rms_push_notifications')->send($message); } } }