[英]iOS push notification not received for Distribution mode
我正在將推送通知集成到我的iOS應用程序中。 我正在按照本教程http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1發送推送。
我可以成功發送推送development mode
。 當我嘗試在Distribution mode
從服務器發送推送時,請不要在設備上接收。
我有
一)創建aps_develoment.cer
為發展宗旨和aps_production.cer
分配的目的
b)從keychain導出push.p12
並轉換為pushChatKey.pem
c)中創建pushChatCertDev.pem
從aps_development.cer
和pushChatCertDis.pem
從aps_production.cer
d)創建combineDev.pem
從pushChatCertDev.pem
和pushChatKey.pem
。 同樣創造combineDis.pem
從pushChatCertDis.pem
和pushChatKey.pem
。
我按照上面的教程成功地從終端發送了push in Development mode
。 PHP腳本是
<?php
$deviceToken ='eff527a7f5f3127d55a63269538498bff2134c6d7b72e4920809d0a102aa04d6';
// Put your private key's passphrase here:
$passphrase = 'Nopass@1234';
// Put your alert message here:
$message = 'TJS push notification test';
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'combineDev.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
// Open a connection to the APNS server
$fp = stream_socket_client(
'ssl://gateway.sandbox.push.apple.com:2195', $err,
$errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
if (!$fp)
exit("Failed to connect: $err $errstr" . PHP_EOL);
echo 'Connected to APNS' . PHP_EOL;
// Create the payload body
$body['aps'] = array(
'alert' => $message,
'sound' => 'default'
);
// Encode the payload as JSON
$payload = json_encode($body);
// Build the binary notification
$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
// Send it to the server
$result = fwrite($fp, $msg, strlen($msg));
if (!$result)
echo 'Message not delivered' . PHP_EOL;
else
echo 'Message successfully delivered' . PHP_EOL;
// Close the connection to the server
fclose($fp);
?>
推送在開發模式下發送到iPhone 4S。 然后我從app商店下載相同的應用程序到我的iPhone 4S。 我將php腳本上傳到我的服務器,並將combineDev.pem
替換為combineDis.pem
。 當我從服務器運行php腳本時,它顯示
Connected to APNS Message successfully delivered
但iPhone 4S沒有收到推送。 我也試圖更換ssl://gateway.sandbox.push.apple.com:2195
通過ssl://gateway.push.apple.com:2195
,但沒有運氣。
請幫忙。 我被困在這里8-10個小時。
謝謝
在上面的代碼中更改行
stream_context_set_option($ctx, 'ssl', 'local_cert', 'combineDev.pem');
至
stream_context_set_option($ctx, 'ssl', 'local_cert', 'combineDis.pem');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.