首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Apple推送通知网关连接,未收到通知

Apple推送通知网关连接,未收到通知
EN

Stack Overflow用户
提问于 2013-05-05 14:34:40
回答 1查看 481关注 0票数 0

我从我的iOS应用程序多次发送通知。为此,我使用APNS-PHP库将其从服务器发送到Apple Push Notification Gateway。

下面是代码。

代码语言:javascript
复制
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);  
    }
}

但是很多时候我没有收到它们,那么有什么可能的解决方案呢?是不是因为我正在连接和断开它。

编写这段代码的更好方法是什么?

EN

回答 1

Stack Overflow用户

发布于 2013-05-05 16:34:21

您是否在ios应用程序中正确接收令牌?

另外,使用这个( https://github.com/jPaolantonio/SimplePush/blob/master/simplepush.php )简短的例子,然后自己修改它。这个例子对我很有效。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16382044

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档