如何使用C#用泰米尔语向IOS发送通知



我正在使用C#开发一个应用程序,它必须向iOS和Android发送通知。在Android中,通知用泰米尔语发送。但用英语向iOS发送通知,效果很好。但是,我怎样才能发送其他语言,如印地语、法语、德语等等

下面是我使用的代码:

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...nn");
Debug.WriteLine(array);
try
{
sslStream.Write(array);
sslStream.Flush();
}
catch
{
Debug.WriteLine("Write failed buddy!!");
}
client.Close();
Debug.WriteLine("Client closed.");

您没有说明问题所在,也没有说明发送消息时会发生什么既然你没有问任何问题,就没有人能帮你

然而,快速浏览一下代码就会发现:

  1. 您假设有效负载的长度永远不会超过255个字符(您将长度的高字节设置为0)
  2. 您将有效负载长度设为Unicode字符数,而不是有效负载的UTF-8表示形式中的字符数。这是正确的吗?这听起来不太可能。我不知道答案,但你应该知道

最新更新