I have a strange problem. I'm developing an app with push notifications, and when the iphone is pluged and I run my app from x-code, if I receive a push notification, my application:didReceiveRemoteNotification:fetchCompletionHandler: method is called, and it runs some code in background, like for example to set the application badge number to ++.
So if I send multiple push notifications, my app badge icon changes.
But when stop x-code and I launch the app outside of x-code (from the iphone) my application:didReceiveRemoteNotification:fetchCompletionHandler: method is not called, and the app icon badge is allways 1, no matter how many push notifications are sended.
This is just an example without importance, but I have some important things to do in that method, like for example, an url link is allways sent into my push notifications, and if application:didReceiveRemoteNotification:fetchCompletionHandler: method is not being called, my url won't load and my app become useless.
Can somebody help me with this? I really need a method to be called when a push notification is received 😐
By the way, this is my payload:
// message here:
$message = 'New content available!';
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
stream_context_set_option($ctx, 'ssl', 'cafile', 'entrust_2048_ca.cer');
// Open a connection to the APNS server
$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,
'sound' => 'default',
'type'=>'Notify',
'content-available'=>1,
'badge' =>1,
'link' => 'http://www.example.com'
);
// Encode the payload as JSON
$payload = json_encode($body);
// Build the binary notification
$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
// Send it to the server
$result = fwrite($fp, $msg, strlen($msg));