[英]iOS push notification received but no badge value
在我的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));
我成功接收到帶有聲音的消息,但我的應用程序圖標沒有徽章值。
您正在嘗試使用字符串值設置徽章:
$body['aps'] = array('alert' => 'This is a test', 'badge' => "1", 'sound' => 'default');
根據Apple文檔中有關有效負載密鑰的描述,與密鑰badge
關聯的值必須為數字。 將其替換為整數值:
$body['aps'] = array('alert' => 'This is a test', 'badge' => 1, 'sound' => 'default');
使用'badge' => 1
而不是'badge' => "1"
嘿@GhostStack確保您必須在applicationDodFinishLaunchingWithOptions
方法中注冊警報/聲音和徽章
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.