【问题标题】:Iphone Push notification in hindi is not received未收到印地语的 iPhone 推送通知
【发布时间】:2015-04-17 07:28:31
【问题描述】:

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

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

并且客户端完美接收。但是当我在警报键上放置一些印地语数据代替“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)

印地语文本被接收为 ???????

【问题讨论】:

    标签: ios asp.net iphone apple-push-notifications


    【解决方案1】:

    试试这个代码,对我来说工作正常.. 已完成更改

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-29
      • 2013-04-14
      • 2011-08-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多