I've developed an app and everything works fine except updating the badge when the app is not running.
I receive the push notification but nothing happens with the badge.
The application request the alert and badge type when registering with Apple.
Any ideas? This is driving me crazy.
This is the code I use to send the push:
<?php
$apnsHost = 'gateway.sandbox.push.apple.com';
$apnsCert = '/usr/local/php/cert.pem';
$apnsPort = 2195;
$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);
$apns = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $error, $errorString, 2, STREAM_CLIENT_CONNECT, $streamContext);
$payload['aps'] = array('alert' => 'Oh hai!', 'badge' => 1);
$output = json_encode($payload);
$token = '1234';
$token = pack('H*', str_replace(' ', '', $token));
$apnsMessage = chr(0) . chr(0) . chr(32) . $token . chr(0) . chr(strlen($output)) . $output;
fwrite($apns, $apnsMessage);
socket_close($apns);
fclose($apns);