[英]Apple Push Notification Gateway Connection, Notification not received
I am sending notifications many a time from my iOS application. 我经常从iOS应用程序发送通知。 For this i have used APNS-PHP library for sending it from server to Apple Push Notification Gateway.
为此,我使用APNS-PHP库将其从服务器发送到Apple Push Notification Gateway。
Here is the code. 这是代码。
public function publishAPush($requestBody){
try {
$toUserId=$requestBody->{KEY_USERID};
$toUserType=$requestBody->{KEY_USERTYPE};
$soundFileName=$requestBody->{"sound"};
$badge=$requestBody->{"badge"};
$customMessage=$requestBody->{"custom"};
$alertMesssage=$requestBody->{"alert"};
if(!empty ($toUserId)){
$push = new ApnsPHP_Push(
ApnsPHP_Abstract::ENVIRONMENT_SANDBOX,
'file.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($deviceToken);
// Set badge icon to "3"
$message->setBadge($badgeCount);
// Set a simple welcome text
$message->setText($alertMesssage);
// Play the default sound
$message->setSound($soundFileName);
$message->setCustomProperty("custom", json_encode($customMessage));
$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)) {
Logger::getRootLogger()->error("Apple Server Error= " . $aErrorQueue);
}else{
Logger::getRootLogger()->info("Message Send successfully to " . $toUserId);
}
}
} catch (Exception $exc) {
Logger::getRootLogger()->error("Publish a Push= " . $exc);
}
}
But it happens that many a times I don't receive them, so what could be a possible solution for it. 但是碰巧很多次我都没有收到,所以可能有解决方案。 Is it because I am connecting and disconnecting it.
是因为我正在连接和断开连接。
What would be a better way to write this code? 编写此代码的更好方法是什么?
do you receive the token in the ios app correctly? 您是否在ios应用程序中正确收到令牌?
also, use this ( https://github.com/jPaolantonio/SimplePush/blob/master/simplepush.php ) short example and then modify it yourself. 另外,请使用此简短示例( https://github.com/jPaolantonio/SimplePush/blob/master/simplepush.php ),然后自己进行修改。 this example is working for me.
这个例子对我有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.