Esempio n. 1
0
 public function sendIOS(Message $message)
 {
     // Prepare message
     // $_message = new \ApnsPHP_Message();
     $_message = new \ApnsPHP_Message_Custom();
     foreach ($message->ios->getTo() as $token) {
         $_message->addRecipient($token);
     }
     // normal ApnsPHP_Message
     $_message->setText($message->ios->getBody());
     $_message->setBadge($message->ios->getBadge());
     $_message->setSound($message->ios->getSound());
     $_message->setContentAvailable($message->ios->isContentAvailable());
     $_message->setCategory($message->ios->getCategory());
     // custom ApnsPHP_Message
     $_message->setTitle($message->ios->getTitle());
     $_message->setLocKey($message->ios->getBodyLocKey());
     $_message->setLocArgs($message->ios->getBodyLocArgs());
     $_message->setLaunchImage($message->ios->getLaunchImage());
     // set additional data (payload data)
     foreach ($message->ios->getData() as $key => $value) {
         $_message->setCustomProperty($key, $value);
     }
     // Connection
     $this->getIOSClient()->connect();
     $this->getIOSClient()->add($_message);
     $this->getIOSClient()->send();
     $this->getIOSClient()->disconnect();
     return $this->getIOSClient()->getErrors(true);
 }
Esempio n. 2
0
 /**
  * Send a push notification using ApnsPHP Library
  * @param string $deviceToken the push token for the mobile device
  * @param string $message the message to display
  * @param string $alertSound the audio file to play, otherwise use the default sound
  * @param string $unlockText if the device is locked, show "Slide to XXX" where XXX is the unlockText
  * @param int $badgeCount the number that should be shown on the springboard badge
  */
 public function SendWithApns($deviceToken, $messageText, $alertSound = 'default', $unlockText = '', $badgeCount = 0)
 {
     $output = new stdClass();
     $output->date = date('Y-m-d H:i:s');
     $output->success = false;
     $output->message = '';
     $push = new ApnsPHP_Push($this->sandboxMode ? ApnsPHP_Abstract::ENVIRONMENT_SANDBOX : ApnsPHP_Abstract::ENVIRONMENT_PRODUCTION, $this->certFilePath);
     $push->setProviderCertificatePassphrase($this->certPassphrase);
     $push->connect();
     $message = new ApnsPHP_Message_Custom($deviceToken);
     $message->setCustomIdentifier("message-1");
     // used to get error details if multiple messages are being sent
     $message->setText($messageText);
     $message->setSound($alertSound);
     $message->setExpiry(10);
     // timeout for connecting to push service
     $message->setActionLocKey($unlockText);
     // appended to "slide to " in the main unlock bar
     // $message->setLocKey(''); // override the text on the app lockscreen message
     $message->setBadge($badgeCount);
     $push->add($message);
     $push->send();
     $push->disconnect();
     // Examine the error message container
     $errors = $push->getErrors();
     $output->success = !empty($errors);
     if (!$output->success) {
         $output->message = print_r($errors, 1);
     }
     return $output;
 }
Esempio n. 3
0
require_once 'ApnsPHP/Autoload.php';
// Instanciate a new ApnsPHP_Push object
$push = new ApnsPHP_Push(ApnsPHP_Abstract::ENVIRONMENT_SANDBOX, 'server_certificates_bundle_sandbox.pem');
// Set the Root Certificate Autority to verify the Apple remote peer
$push->setRootCertificationAuthority('entrust_root_certification_authority.pem');
// Connect to the Apple Push Notification Service
$push->connect();
// Instantiate a new Message with a single recipient
$message = new ApnsPHP_Message_Custom('1e82db91c7ceddd72bf33d74ae052ac9c84a065b35148ac401388843106a7485');
// Set a custom identifier. To get back this identifier use the getCustomIdentifier() method
// over a ApnsPHP_Message object retrieved with the getErrors() message.
$message->setCustomIdentifier("Message-Badge-3");
// Set badge icon to "3"
$message->setBadge(3);
// Set a simple welcome text
$message->setText('Hello APNs-enabled device!');
// Play the default sound
$message->setSound();
// Set a custom property
$message->setCustomProperty('acme2', array('bang', 'whiz'));
// Set the expiry value to 30 seconds
$message->setExpiry(30);
// Set the "View" button title.
$message->setActionLocKey('Show me!');
// Set the alert-message string and variable string values to appear in place of the format specifiers.
$message->setLocKey('Hello %1$@, you have %2$@ new messages!');
// This will overwrite the text specified with setText() method.
$message->setLocArgs(array('Steve', 5));
// Set the filename of an image file in the application bundle.
$message->setLaunchImage('DefaultAlert.png');
// Add the message to the message queue
Esempio n. 4
0
 // Connect to the Apple Push Notification Service
 $push->connect();
 // Instantiate a new Message with a single recipient
 foreach ($res1 as $row) {
     $dt = $row['device_token'];
     //echo $dt."<br>.";
     if (strlen($row['device_token']) == 64) {
         //echo $row['device_token']."<br><hr>";
         $message = new ApnsPHP_Message_Custom($dt);
         // Set a custom identifier. To get back this identifier use the getCustomIdentifier() method
         // over a ApnsPHP_Message object retrieved with the getErrors() message.
         $message->setCustomIdentifier("Message-Badge-1");
         // Set badge icon to "3"
         $message->setBadge(1);
         // Set a simple welcome text
         $message->setText($row['msg']);
         // Play the default sound
         $message->setSound();
         $message->setCat($row['cat']);
         $message->setCustomProperty('ticket_hash', $row['ticket_hash']);
         //$message->setCustomProperty('category', 'lock');
         /*
         $message->setCustomProperty('a', $row['ticket_action']);
         $message->setCustomProperty('id', $row['ticket_id']);
         $message->setCustomProperty('ui', $row['ticket_user_init']);
         */
         // Set the expiry value to 30 seconds
         $message->setExpiry(300);
         // Add the message to the message queue
         $push->add($message);
         // Send all messages in the message queue