繁体   English   中英

未收到印地语中的Iphone Push通知

[英]Iphone Push notification in hindi is not received

我正在从asp.net应用程序发送Iphone的推送通知,就像这样-

字符串msg5 =“ {\\” aps \\“:{\\” NewsId \\“:3156,\\” NewCat \\“:\\” Agra \\“,\\” Date1 \\“:\\” 11Apr2015 \\“,\\”内容可用\\ “:1,\\” 警报\\ “:\\” 的HelloWorld \\ “\\ ”声\\“:\\ ”默认\\“,\\ ”徽章\\“:2}}”;

并被客户端完美接收。 但是,当我在警报键上放置一些Hindi数据代替“ HelloWorld”时,客户端不会收到通知。 请向我解释是什么问题。 我发送通知的代码是-

 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();
        }

但是我使用默认编码代替UTF8像这样

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

印地语文本的接收方式为?????

试试这个代码,对我来说很好。

写b1.length而不是msg5.length(因为印地文的长度与原始文本不同)。

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();
        }


    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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