0
votes

So. I installed my app and under setting it appears that my app is registered for push notification. I also got the token , made the pem file , checked to see if it is correctly used by running this command

apn stefanandrei$ openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert apns-dev.pem -debug -showcerts -CAfile server-ca-cert.pem

I am using this php code:

// send our authentification file
stream_context_set_option($ctx, 'ssl', 'local_cert', 'apns-dev.pem'); 

// open a connection to the sandbox server
$apnsConnection = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx); 

// creating the notification message (256 Byte max)

// your device token here
$deviceToken = 'ba672efe 4d6b5b7b db89a08a e9b36da2 ada14b00 df2f0b36 3eb6515b 08d57879'; 

// your message goes here
$message = "Your push notification text goes here.";

// define a sound file if you want here
$sound = 'mySoundFile.caf'; //name of the sound file inside the XCode project.

// Construct the notification payload
$body = array();
$body['aps'] = array('alert' => $message);
$badge = (int)$argv[2]; // a number which will be displayed over the apps icon
if ($badge)
{
  $body['aps']['badge'] = $badge;
}
if ($sound)
{
  $body['aps']['sound'] = $sound;
}
$payload = json_encode($body);

// remove blanks and pack it.
$msg = chr(0) . pack("n",32) . pack('H*', str_replace(' ', '', $deviceToken)) . pack("n",strlen($payload)) . $payload;
echo $msg;

// push the message through APNS
fwrite($apnsConnection, $msg); 

//close APNS connection
fclose($apnsConnection);
?>
<code>

The problem is that don't receive a notification.I don't receive anything .What can i do.

3
i used tried easy apns but it couldn't connect.It just unregistered my device. I don't know hot to test this.flaviusilaghi

3 Answers

0
votes

One option is to use the enhanced notification format to send the notification. When you do this you will receive a error from the apns servers if they detect any. That way you might be able to make sense on whats going on.

0
votes

Remove The Space form device token ba672efe4d6b5b7bdb89a08ae9b36da2ada14b00 df2f0b363eb6515b08d57879 than try to send notification.

0
votes

We send push notification by two methods in iOS:

  1. By using .net backend.: Create a .p12 file; see How to send Push notification using .net backend.

  2. Php backened.:- Create a .pem file; see Create “.pem” file for push mail (notification) for php backend.