簡體   English   中英

Apple Push Notification Gateway連接,未收到通知

[英]Apple Push Notification Gateway Connection, Notification not received

我經常從iOS應用程序發送通知。 為此,我使用APNS-PHP庫將其從服務器發送到Apple Push Notification Gateway。

這是代碼。

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);  
    }
}

但是碰巧很多次我都沒有收到,所以可能有解決方案。 是因為我正在連接和斷開連接。

編寫此代碼的更好方法是什么?

您是否在ios應用程序中正確收到令牌?

另外,請使用此簡短示例( https://github.com/jPaolantonio/SimplePush/blob/master/simplepush.php ),然后自己進行修改。 這個例子對我有用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM