簡體   English   中英

Apple推送通知服務-設備上沒有通知

[英]Apple push notification service - no notification on device

這個問題使我發瘋。 我正在實施APNS。 我已經谷歌,並遵循了一些教程。 我實現了服務器,它似乎可以正常工作,找到的是以下代碼:

<?php

$deviceToken = 'XXXX';
// Passphrase for the private key (ck.pem file)
// $pass = '';
// Get the parameters from http get or from command line
$message = $_GET['message'] or $message = $argv[1] or $message = 'Message received from javacom';
$badge = (int)$_GET['badge'] or $badge = (int)$argv[2];
$sound = $_GET['sound'] or $sound = $argv[3];

// Construct the notification payload
$body = array();
$body['aps'] = array('alert' => $message);
if ($badge)
    $body['aps']['badge'] = $badge;

if ($sound)
    $body['aps']['sound'] = $sound;

/* End of Configurable Items */

$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');
// assume the private key passphase was removed.
//stream_context_set_option($ctx, 'ssl', 'passphrase', $pass);
$fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx); // for production change the server to ssl://gateway.push.apple.com:219
if (!$fp) {
    print "Failed to connect $err $errstr\n";
    return;
} else {
    print "Connection OK\n";
}

$payload = json_encode($body);
$msg = chr(0) . pack("n",32) . pack('H*', str_replace(' ', '', $deviceToken)) . pack("n",strlen($payload)) . $payload;
print "sending message :" . $payload . "\n";
fwrite($fp, $msg);
fclose($fp);

?>

似乎工作正常。 我沒有任何錯誤。 但是我的設備上沒有任何推送通知。 我不知道錯誤可能在哪里。 我還實現了反饋腳本。 無錯誤,無輸出。 我的應用程序也已准備好。 提前致謝。

蘋果公司剛剛發布了名為“對推送通知進行故障排除”的技術說明。 它具有發送和接收的技巧。 也許那里有幫助。

暫無
暫無

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

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