ApnsPHP
ApnsPHP copied to clipboard
Not Connected to Push Notification Service
Hello,
I am having an issue connecting to the Push notification server, it connects to the tls though. I did follow the certificate procedure from this url The code for APNs call is given below:
`date_default_timezone_set('Europe/London'); error_reporting(-1); require_once '/path_to_ApnsPHP/Autoload.php'; $path_cer = 'server_certificates_bundle_sandbox.pem'; $push = new ApnsPHP_Push( ApnsPHP_Abstract::ENVIRONMENT_SANDBOX, $path_cer );
// Set the Provider Certificate passphrase
//$push->setProviderCertificatePassphrase('test');
// Set the Root Certificate Autority to verify the Apple remote peer
// $push->setRootCertificationAuthority('entrust_root_certification_authority.pem');
$push->connect();
$message = new ApnsPHP_Message($device_id);
$message->setCustomIdentifier("Message-Badge-3");
$message->setBadge(3);
$message->setText('Custom Text');
$message->setSound();
$message->setCustomProperty('acme2', array('bang', 'whiz'));
$message->setCustomProperty('acme3', array('bing', 'bong'));
$message->setExpiry(30);
$push->add($message);
$push->send();
$push->disconnect();
$aErrorQueue = $push->getErrors();
if (!empty($aErrorQueue)) {
var_dump($aErrorQueue);
}``
However, I commented the these line in the Abstract.php
`$streamContext = stream_context_create(array('ssl' => array( 'verify_peer' => isset($this->_sRootCertificationAuthorityFile), 'cafile' => $this->_sRootCertificationAuthorityFile, 'local_cert' => $this->_sProviderCertificateFile )));
if (!empty($this->_sProviderCertificatePassphrase)) {
stream_context_set_option($streamContext, 'ssl',
'passphrase', $this->_sProviderCertificatePassphrase);
}
$this->_hSocket = stream_socket_client($sURL, $nError, $sError,
$this->_nConnectTimeout, STREAM_CLIENT_CONNECT, $streamContext);
if (!$this->_hSocket) {
throw new ApnsPHP_Exception(
"Unable to connect to '{$sURL}': {$sError} ({$nError})"
);
}
stream_set_blocking($this->_hSocket, 0);
stream_set_write_buffer($this->_hSocket, 0);`
The error that I got is attached.
And if I uncomment the lines in Abstarct.php, I get a different set of errors:
@Zaeembinrehman Did you ever find a solution?