2013-05-05 3 views
0

iOS 응용 프로그램에서 여러 번 알림을 보냅니다. 이를 위해 APNS-PHP 라이브러리를 사용하여 서버에서 Apple Push Notification Gateway로 전송했습니다.Apple 푸시 알림 게이트웨이 연결, 알림을받지 못했습니다.

다음은 코드입니다.

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

그러나 나는 그것을받지 못하는 경우가 많기 때문에 가능한 해결책이 될 수 있습니다. 내가 연결하고 연결을 끊고 있기 때문일까요?

이 코드를 작성하는 더 좋은 방법은 무엇입니까?

답변