简体   繁体   English

推送iOs通知西班牙语字符

[英]Push iOs notifications spanish characters

I have a problem with the Spanish character 'ñ' and push iOs notifications. 我的西班牙语字符“ñ”有问题,并推送了iOs通知。 I send notifications using a PHP script. 我使用PHP脚本发送通知。 Before send it I encode the message as utf8 and it is well done. 在发送之前,我将消息编码为utf8,并且做得很好。 The problem is that when I send the notification with a 'ñ' in the payload I don't receive it, but with other special character as 'á', 'é',..., I receive it without any problem. 问题是,当我在有效负载中发送带有“?”的通知时,我没有收到该通知,但使用其他特殊字符(如“á”,“é”,...)接收时,却没有任何问题。

$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;

EDIT: 编辑:

Special characters as 'ñ' are sent correctly, my problem was that I sent more data than $text ($text variable was written to explain the code better). 特殊字符'ñ'的发送正确,我的问题是我发送的数据比$ text多(编写了$ text变量以更好地解释代码)。 In iOs push notifications there is a payload size limit and my message exceeded it, so the device didn't received it. 在iOs推送通知中,有一个有效负载大小限制,而我的消息超出了该限制,因此设备未收到该限制。 It only happened with one text in my application, because it was the largest, and it was the only one with an 'ñ'. 它仅在我的应用程序中出现一个文本,因为它是最大的文本,并且是唯一带有“ñ”的文本。 So, if you don't receive some message check the number of characters. 因此,如果您没有收到任何消息,请检查字符数。

Try using entites. 尝试使用实体。

$text="España"
...

Saludos desde Suiza 萨伊萨乌德酒

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM