示例#1
0
// 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
$push->add($message);
// Send all messages in the message queue
$push->send();
// Disconnect from the Apple Push Notification Service
$push->disconnect();
// Examine the error message container
$aErrorQueue = $push->getErrors();
if (!empty($aErrorQueue)) {
    var_dump($aErrorQueue);
}
示例#2
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);
 }