I am integrating push notification into my iOS app. I am following this tutorial http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1 to send push.
I can successfully sent push on development mode
. When I tried to send push from server on Distribution mode
, push not received on device.
I have
a) created aps_develoment.cer
for development purpose and aps_production.cer
for distribution purpose
b) export push.p12
from keychain and converted to pushChatKey.pem
c) created pushChatCertDev.pem
from aps_development.cer
and pushChatCertDis.pem
from aps_production.cer
d) created combineDev.pem
from pushChatCertDev.pem
and pushChatKey.pem
. Similarly created combineDis.pem
from pushChatCertDis.pem
and pushChatKey.pem
.
I followed the above tutorial and successfully sent push in Development mode
from terminal. PHP script is
<?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);
?>
Push sent into iPhone 4S on development mode. Then I download same app from app store into my iPhone 4S. I uploaded php script into my server and replace combineDev.pem
with combineDis.pem
. When I run php script from server it shows
Connected to APNS Message successfully delivered
but no push received at iPhone 4S. I also tried with replacing ssl://gateway.sandbox.push.apple.com:2195
by ssl://gateway.push.apple.com:2195
but no luck.
Please help. I am stuck here for 8-10 hours.
Thanks
In your above code change the line
stream_context_set_option($ctx, 'ssl', 'local_cert', 'combineDev.pem');
to
stream_context_set_option($ctx, 'ssl', 'local_cert', 'combineDis.pem');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.