Reputation: 117
Hi I’m trying to create push notification in my app I’m getting device token and php script I have written by see some tutorials but now I’m not getting the push notification in my device not don’t where I have done wrong here please help me out..
this is my php script ...
<?php
if($_POST['message']){
$deviceToken ='here i have given my device token ';
$message = stripcslashes($_POST['message']);
$payload = '{
"aps" :
{
"alert" :"'.$message.'",
"badge" : 1,
"sound" : "bingbong.aiff"
}
}';
$ctx = stream_context_create();
stream_context_set_option($ctx,'ssl', 'local_cert','ck.pem');
stream_context_set_option($ctx,'ssl','passphrase', 'bali');
$fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195',$err,$errstr,60,STREAM_CLIENT_CONNECT,$ctx);
if(!fp){
print "Failed to connect $err $errstrn";
return;
}else{
print "notifications sent!";
}
$devArray = array();
$devArray[] = $deviceToken;
foreach($devArray as $deviceToken){
$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);
}
?>
i worte this script using this tutorial here
using this php script im trying to run on my local host but not working pls tell where im doing wrong in the script
thanks.
Upvotes: 0
Views: 122
Reputation: 117
hi guys i figured out where i was wrong
pack("H*", str_replace(' ',' ',$deviceToken)).
in my about code the asterisk symbol was missing near h after putting asterisk its working fine for me
thanks for ur replays
Upvotes: 1
Reputation: 5684
server should provide some error/success response, read answer from socket before closing it, also check connection error.
Upvotes: 0