php - 推送 iOS 通知西类牙语字符

标签 php ios push-notification apple-push-notifications

我对西类牙字符“ñ”和推送 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/

相关文章:

Javascript 警报正在打开 PHP 包含文件并且不停留在主页上

php - 计算特定mysql列不为空的行数

iOS:如何在没有 "Potential leak"警告的情况下将 ABAddressBookRef 存储在属性中?

ios - Swift ios 检查是否在 ios9 和 ios10 中启用了远程推送通知

php - jQuery POST 到 PHP 没有获得成功功能

php - 管理部分在 Magento 中自动注销

windows-phone-8 - WNS - 已交付瓷砖但未交付 Toast

iphone - Apple PNS(推送通知服务)示例代码

ios - 无法将 base64 编码的图像添加到 vCard

ios - 随 secret 码生成器 Swift 3?