[英]iOS push notification received but no badge value
In my iOS Swift app i can send push notifications with this php code: 在我的iOS Swift应用中,我可以使用以下php代码发送推送通知:
$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. 我成功接收到带有声音的消息,但我的应用程序图标没有徽章值。
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. 根据Apple文档中有关有效负载密钥的描述,与密钥
badge
关联的值必须为数字。 Replace it with an integer value : 将其替换为整数值:
$body['aps'] = array('alert' => 'This is a test', 'badge' => 1, 'sound' => 'default');
使用'badge' => 1
而不是'badge' => "1"
Hey @GhostStack make sure you have to register for alert/sound and badge in applicationDodFinishLaunchingWithOptions
method 嘿@GhostStack确保您必须在
applicationDodFinishLaunchingWithOptions
方法中注册警报/声音和徽章
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.