开发者

Enhanced Apple Push Notification: Response error at provider server

i am working on a project in PHP which requires me to push an alert notification on APNS server. I have used enhanced push notification format. but I am not receiving response as specified by the APNS docs. I am getting response in three digits usually 133, 132, 154, 138, etc. Which I concluded to be Status signs, eg. 133 is 1, 3, 3. but now I have also received 139. so I doubt that my interpretation of response is wrong. But I am not getting where it is wrong. And important thing is though I am receiving these responses Alert is getting pushed and I am receiving notification on my iPhone as well as on iPad.

My code is as follows:

$payload['aps'] = array('alert' => $message, 'badge' => 1, 'sound' => 'default');

$apnsHost = 'gateway.sandbox.push.apple.com'; 

$apnsPort = 2195; // default port

$apnsCert = 'apns-dev.pem'; // APNS crtificate.

$passPhrase = '';

$streamContext = stream_context_create();

stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);

stream_context_set_option($streamContext, 'ssl', 'passphrase', $passPhrase);

try{

$apns = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $error, $errorString, 60, STREAM_CLIENT_CONNECT, $streamContext);

if (!$apns) {
    print "Failed to connect {$error} {$errorString}\n";
}
else {   
    // Sending the payload

    $apnsMessage = chr(0) . pack('n', 1) . pack('n', $nid) . pack('n', time() + 604800) . pack('n', 32) . pack('H*', str_replace(' ', '', $alert_开发者_开发技巧device_token)) .  pack('n', strlen($payload)) . $payload;

    echo 'APNS Message: ' . $apnsMessage;

    $fwrite = fwrite($apns, $apnsMessage);

    echo 'APNS response: ' . $fwrite;

And when this get executed i got the following response printed on the browser:

APNS Message: ��=ŸÂ� òc6–U:õŸŠ ¸Þ ÷ćÚ0ßqšÊzÂífÕnZ�`{"aps":{"alert":"Your EUR\/USD SELL alert price has been reached!","badge":1,"sound":"default"}}APNS response: 139

Can anyone please tell me what does this 139 means here. am doing anything wrong here.


The echoed "139" is the return value of fwrite(). It's the number of bytes written by fwrite()

See: PHP: fwrite

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜