I'm developing an application using C# which have to send notification to both iOS and Android.In Android notification send in Tamil. But send a notification to iOS in English it working good. But, how can I send other languages like Hindi, French, German and so on.
Below is the code which I used:
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.");
Aucun commentaire:
Enregistrer un commentaire