Reputation: 153
In my iOS Swift app i can send push notifications with this php code:
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', 'APPNAME');
// 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);
}
$body['aps'] = array('alert' => 'This is a test', 'badge' => "1", 'sound' => 'default');
$payload = json_encode($body);
$msg = chr(0) . pack('n', 32) . pack('H*', DEVICE_TOKEN) . pack('n', strlen($payload)) . $payload;
$result = fwrite($fp, $msg, strlen($msg));
I successfully receive the message, with the sound, but my app icon gets not badge value.
Upvotes: 1
Views: 349
Reputation: 501
Hey @GhostStack make sure you have to register for alert/sound and badge in applicationDodFinishLaunchingWithOptions
method
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
Upvotes: 0
Reputation: 3894
You are trying to set your badge with a string value :
$body['aps'] = array('alert' => 'This is a test', 'badge' => "1", 'sound' => 'default');
According to the description of payload keys from Apple documentation, the value associated with the key badge
must be a number. Replace it with an integer value :
$body['aps'] = array('alert' => 'This is a test', 'badge' => 1, 'sound' => 'default');
Upvotes: 2