2016-06-11 36 views
0

我正在開發一個使用C#的應用程序,它必須向iOS和Android發送通知。但發送通知到iOS的英文它運作良好。但是,我怎樣才能發送其他語言,如印地文,法文,德文等。如何以坦米爾語言向IOS發送通知使用C#

下面是我使用的代碼:

string devicetocken = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";// iphone device token 
int port = 2195; 
String hostname = "gateway.sandbox.push.apple.com"; 
string certificatePath = @"Certificates.pfx"; 
string certificatePassword = ""; 
X509Certificate2 clientCertificate = new X509Certificate2(certificatePath, certificatePassword, X509KeyStorageFlags.MachineKeySet); 
X509Certificate2Collection certificatesCollection = new X509Certificate2Collection(clientCertificate); 

TcpClient client = new TcpClient(hostname, port); 
SslStream sslStream = new SslStream(client.GetStream(),false,new RemoteCertificateValidationCallback(ValidateServerCertificate),null); 
try 
{ 
    sslStream.AuthenticateAsClient(hostname, certificatesCollection, SslProtocols.Default, false); 
} 
catch (AuthenticationException ex) 
{ 
    Console.WriteLine("Authentication failed"); 
    client.Close(); 
    return; 
} 
MemoryStream memoryStream = new MemoryStream(); 
BinaryWriter writer = new BinaryWriter(memoryStream); 
writer.Write((byte)0); //The command 
writer.Write((byte)0); //The first byte of the deviceId length (big-endian first byte) 
writer.Write((byte)32); //The deviceId length (big-endian second byte) 
int len = devicetocken.Length; 
int len_half = len/2; 
byte[] bs = new byte[len_half]; 
for (int i = 0; i != len_half; i++) 
{ 
    bs[i] = (byte)Int32.Parse(devicetocken.Substring(i * 2, 2), System.Globalization.NumberStyles.HexNumber); 
} 
byte[] b0 = bs; 
writer.Write(b0); 
String payload; 
string strmsgbody = ""; 
strmsgbody = "சென்னை"; 
//strmsgbody = "Chennai"; 
Debug.WriteLine("during testing via device!"); 
payload = "{\"aps\":{\"alert\":\"" + strmsgbody + "\",\"sound\":\"mailsent.wav\"},\"acme1\":\"bar\",\"acme2\":42}"; 
writer.Write((byte)0); //First byte of payload length; (big-endian first byte) 
writer.Write((byte)payload.Length);  //payload length (big-endian second byte) 
byte[] b1 = System.Text.Encoding.UTF8.GetBytes(payload); 
writer.Write(b1); 
writer.Flush(); 
byte[] array = memoryStream.ToArray(); 
Debug.WriteLine("This is being sent...\n\n"); 
Debug.WriteLine(array); 
try 
{ 
    sslStream.Write(array); 
    sslStream.Flush(); 
} 
catch 
{ 
    Debug.WriteLine("Write failed buddy!!"); 
} 

client.Close(); 
Debug.WriteLine("Client closed."); 
+0

最後通過使用PushSharp找到了一個解決方案。 –

+0

請把它作爲答案 – SibiCoder

回答

0

你不說是什麼問題 - 你不說,當你發送郵件會發生什麼。 由於您沒有提出任何問題,因此沒有人能夠爲您提供幫助。

然而,在代碼快速瀏覽顯示:

  1. 你假設有效載荷將永遠不能超過255個字符(你是長度的高字節設置爲0)。
  2. 您正在使有效負載長度成爲Unicode字符的數量,而不是有效負載的UTF-8表示中的字符數。它是否正確?聽起來不太可能。我不知道答案,但你應該。
+0

嗨nugae,我問我的問題,如如何發送推送通知IOS移動..上述代碼工作英語,但我想發送它在其他語言。 –