我对西类牙字符“ñ”和推送 iOs 通知有疑问。 我使用 PHP 脚本发送通知。在发送之前,我将消息编码为 utf8 并且做得很好。问题是,当我在有效载荷中发送带有“ñ”的通知时,我没有收到它,但是带有其他特殊字符如“á”,“é”,......,我收到它没有任何问题。
$text = "España";
$json = '{"data":{"text":"' . $text . '"}}';
$passphrase = 'passphase';
$message = utf8_encode($json);
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
// 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;
// Create the payload body
$body['aps'] = array(
'alert' => $message,
'sound' => 'default'
);
// Encode the payload as JSON
$payload = json_encode($body);
// Build the binary notification
$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken[$i]) . pack('n', strlen($payload)) . $payload;
// Send it to the server
$result = fwrite($fp, $msg, strlen($msg));
if (!$result)
echo 'Message not delivered' . PHP_EOL;
else
echo 'Message successfully delivered' . PHP_EOL;
编辑:
“ñ”等特殊字符被正确发送,我的问题是我发送的数据比 $text 多(写入 $text 变量是为了更好地解释代码)。在 iOs 推送通知中,有一个负载大小限制,我的消息超过了它,所以设备没有收到它。它只发生在我的应用程序中的一个文本中,因为它是最大的,并且是唯一带有“ñ”的文本。 因此,如果您没有收到消息,请检查字符数。
最佳答案
尝试使用实体。
$text="España"
...
祝你健康
关于php - 推送 iOS 通知西类牙语字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22023414/