简体   繁体   中英

Iphone Push notification in hindi is not received

I am sending push notification for Iphone from an asp.net application Like this-

String msg5 = "{\\"aps\\":{\\"NewsId\\":3156,\\"NewCat\\":\\"Agra\\",\\"Date1\\":\\"11Apr2015\\",\\"content-available\\":1,\\"alert\\":\\"HelloWorld\\",\\"sound\\":\\"default\\",\\"badge\\":2}}";

and it is received by the client side perfectly. But When I place some Hindi Data in place of "HelloWorld" on alert key, Notification is not received by client side. Please Explain me what is the issue. My code to send Notification is -

 public static void pushMessage(string deviceID)
    {
        int port = 2195;
        String hostname = "gateway.sandbox.push.apple.com";
        String certificatePath = System.Web.Hosting.HostingEnvironment.MapPath("~/Certificates.p12");
        //X509Certificate2 clientCertificate = new X509Certificate2(System.IO.File.ReadAllBytes(certificatePath), "");//password

        X509Certificate2 clientCertificate = new X509Certificate2(System.IO.File.ReadAllBytes(certificatePath), "", X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.Exportable);
        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.Tls, false);
            MemoryStream memoryStream = new MemoryStream();
            BinaryWriter writer = new BinaryWriter(memoryStream);
            writer.Write((byte)0);
            writer.Write((byte)0);
            writer.Write((byte)32);

            writer.Write(HexStringToByteArray(deviceID.ToUpper()));
            String msg4 = "{\"aps\":{\"NewsId\":3156,\"NewCat\":\"Agra\",\"Date1\":\"11Apr2015\",\"content-available\":1,\"alert\":\"मुख्यमंत्री ने जर्मनी के उद्यमियों को राज्य में निवेश के लिए आमंत्रित किया\",\"sound\":\"default\",\"badge\":2}}";
            String msg5 = "{\"aps\":{\"NewsId\":3156,\"NewCat\":\"Agra\",\"Date1\":\"11Apr2015\",\"content-available\":1,\"alert\":\"HelloWorld\",\"sound\":\"default\",\"badge\":2}}";
            writer.Write((byte)0);
            writer.Write((byte)msg5.Length);
            byte[] b1 = System.Text.Encoding.UTF8.GetBytes(msg5);
            writer.Write(b1);
            writer.Flush();
            byte[] array = memoryStream.ToArray();
            sslStream.Write(array);
            sslStream.Flush();
            client.Close();
        }
        catch (System.Security.Authentication.AuthenticationException ex)
        {
            client.Close();
        }
        catch (Exception e)
        {
            client.Close();
        }

But In place of UTF8 I use default encoding Like this

byte[] b1 = Encoding.UTF8.GetBytes(msg5)

Hindi text is received as ?????

Try this code, working fine for me.. Changes done

write b1.length instead of msg5.length(as in hindi length vary from original text).

public static void pushMessage(string deviceID, string text)
    {
        int port = 2195;
        String hostname = "gateway.sandbox.push.apple.com";
        String certificatePath = System.Web.Hosting.HostingEnvironment.MapPath("~/cert.p12");

        X509Certificate2 clientCertificate = new X509Certificate2(System.IO.File.ReadAllBytes(certificatePath), "", X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.Exportable);
        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.Tls, false);
            MemoryStream memoryStream = new MemoryStream();
            BinaryWriter writer = new BinaryWriter(memoryStream);
            writer.Write((byte)0);
            writer.Write((byte)0);
            writer.Write((byte)32);

            writer.Write(HexStringToByteArray(deviceID.ToUpper()));
            String msg5 = "{\"aps\":{\"NewsId\":3156, \"alert\":\"" + text + "\",\"content-available\":\"1\"}}";
            writer.Write((byte)0);

            byte[] b1 = Encoding.UTF8.GetBytes(msg5);
            writer.Write((byte)b1.Length);
            writer.Write(b1);
            writer.Flush();
            byte[] array = memoryStream.ToArray();
            sslStream.Write(array);
            sslStream.Flush();
            client.Close();
        }
        catch (System.Security.Authentication.AuthenticationException ex)
        {
            client.Close();
        }
        catch (Exception e)
        {
            client.Close();
        }


    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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