Do you know how to sent push notifications to IOS app from php?
It's best answer for somebody http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1
But it doesn't work:
$production = 0; $passphrase = "kaka"; $deviceToken = "bf38e156 29adac02 6b9b2ec6 35aa4381 df90df65 8238a13c d7f55261 798c3923"; $message = "Hello people! What are you doing?"; $deviceToken = str_replace(" ", "", $deviceToken); // Create a Stream $ctx = stream_context_create(); // Define the certificate to use stream_context_set_option($ctx, "ssl", "local_cert", "CerAndKey.pem"); // Passphrase to the certificate //stream_context_set_option($ctx, "ssl", "passphrase", $passphrase); stream_context_set_option($ctx, "ssl", "verify_peer", true); // load certificate stream_context_set_option($ctx, "ssl", "cafile", "CerAndKey.pem"); if ($production) { $gateway = "gateway.push.apple.com:2195"; } else { $gateway = "gateway.sandbox.push.apple.com:2195"; } $fp = stream_socket_client($gateway, $err, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx); if (!$fp) exit("Failed to connect amarnew: $err $errstr" . PHP_EOL); echo "Connected to APNS" . PHP_EOL; // Create the payload body $body["aps"] = array( "badge" => +1, "alert" => $message, "sound" => "default" ); $payload = json_encode($body); // Build the binary notification $msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload; // Ensure that blocking is disabled //stream_set_blocking($fp, 0); // Send it to the server $result = fwrite($fp, $msg, strlen($msg)); print_r($result); if (!$result) echo 'Message not delivered' . PHP_EOL; else echo 'Message successfully delivered amar '.$message. PHP_EOL; // Close the connection to the server fclose($fp);
+1 is not allowed for badge
Store the badge number where you store the device tokens and update it with every push notification.