I implement a push notification in my application. Push notification is successfully implemented.But there is one issue for updating badge number.
(I am talking about when app in not running)
If i send +2 then badge is set to 2.
if i send +5 then badge is set to 5.
I know that there is badge is 0 initially.So nothing on the app icon.
Now i send a push notification with badge = +2 and badge is set to 2.
Now i again send push notification with badge = +3.
"There must be badge set to 2 + 3 = 5. "
But badge is set to 3 , not 5.
it means badge number is just replaced not add to current badge number.
So what should be the problem with increasing badge when notification arrives.
My php script is :
$passphrase = ‘test123’;
$message = “from myApp+ Admin”;
$ctx = stream_context_create();
stream_context_set_option($ctx, ‘ssl’, ‘local_cert’, ‘myApp.pem’);
stream_context_set_option($ctx, ‘ssl’, ‘passphrase’, $passphrase);
$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;
$body[‘aps’] = array(
‘alert’ => $message,
‘badge’ => +1,
‘sound’ => ‘default’
);
$payload = json_encode($body);
print_r($payload);
$arr1 = array (“your device token1”);
//foreach($arr1 as $value)
//{
//echo $deviceToken = $value->device_token;
$deviceToken = “2f9491d64760c7q5213cf06ff3g6aa8e29r7b5104a00123faa151b92d34023o6”;
$msg = chr(0) . pack(‘n’, 32) . pack(‘H*’, $deviceToken) . pack(‘n’, strlen($payload)) . $payload;
$result = fwrite($fp, $msg, strlen($msg));
/*if (!$result)
echo ‘Message not delivered’ . PHP_EOL;
else
echo ‘Message successfully delivered’ . PHP_EOL;//fwrite($fp, $msg, strlen($msg));*/
//}
fclose($fp);
echo ‘notification sent successfully.’;
Please help me.
Also i try to sending “+2” and “+3”(as a string) , but string is not working.
I think only number value is valid for badge number.
What should i do for increase badge on my app icon , not just replace.
I test it in iPhone 4s with ios 7.0.1 and also ipad with ios 5.1.1
Thank you in advance.
Bhavin