コード例 #1
0
 public function sendPushNotification(Notification $notification)
 {
     $sm = $this->getServiceLocator();
     $objectManager = $sm->get('Doctrine\\ORM\\EntityManager');
     $config = $sm->get('Config');
     if (!isset($config['urban-airship'])) {
         throw new \Exception('Urban Airship configuration is missing. Please make sure `config/autoload/urban-airship.local.php` exists in installation path.');
     } else {
         if (!isset($config['urban-airship']['api-key']) || $config['urban-airship']['api-key']) {
             throw new \Exception('Urban Airship API key is missing. Please make sure `config/autoload/urban-airship.local.php` exists in installation path and that all variables are set correctly.');
         } else {
             if (!isset($config['urban-airship']['api-secret']) || $config['urban-airship']['api-secret']) {
                 throw new \Exception('Urban Airship API secret is missing. Please make sure `config/autoload/urban-airship.local.php` exists in installation path and that all variables are set correctly.');
             }
         }
     }
     UALog::setLogHandlers(array(new StreamHandler('logs' . DIRECTORY_SEPARATOR . 'urban_airship.' . date('Y-m-d') . '.log', Logger::DEBUG)));
     $airship = new Airship($config['urban-airship']['api-key'], $config['urban-airship']['api-secret']);
     try {
         $response = $airship->push()->setAudience(P\deviceToken($device->getDeviceToken()))->setNotification(P\notification($message))->setDeviceTypes(P\deviceTypes($device->getDeviceType()))->send();
         if ($response->ok) {
             $notification->setStatus('sent');
             $notification->setOperationId($response->operation_id);
             $notification->setPushIds($response->push_ids);
         } else {
             $notification->setStatus('failed');
         }
         $objectManager->persist($notification);
         $objectManager->flush();
     } catch (AirshipException $e) {
         $error = $this->logError($e->getCode(), $e->getMessage(), __FILE__, __LINE__, $e->getTrace());
         $notification->setStatus('failed');
         $notification->setError($error);
         $objectManager->persist($notification);
         $objectManager->flush();
         throw $e;
     }
 }
コード例 #2
0
 /**
  * @expectedException InvalidArgumentException
  */
 public function testInvalidDeviceToken()
 {
     P\deviceToken(dt . "more");
 }