2014-02-25 37 views
0

我對西班牙字符'ñ'有問題,並推送iOs通知。 我使用PHP腳本發送通知。在發送之前,我將消息編碼爲utf8,並且做得很好。問題是,當我在有效載荷中發送帶''的通知時,我沒有收到它,但是以其他特殊字符'á','é',...收到它,沒有任何問題。推送iOs通知西班牙語字符

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

編輯:

特殊字符「N」正確地發送,我的問題是,我發送更多的數據超過$文本($文本變量寫更好地解釋代碼)。在iOs推送通知中,有一個有效載荷大小限制,我的信息超過了它,所以設備沒有收到它。它只發生在我的應用程序中的一個文本中,因爲它是最大的,並且它是唯一一個帶有' - '的文本。 所以,如果你沒有收到一些消息檢查字符的數量。

回答

1

嘗試使用entites。

$text="España" 
... 

Saludos desde西扎