我正在从asp.net应用程序发送Iphone的推送通知像这样 -
字符串msg5 =" {\" aps \":{\" NewsId \":3156,\" NewCat \": \"阿格拉\" \"日期1 \":\" 11Apr2015 \" \"内容可用\&#34 ;: 1,\"警报\":\"的HelloWorld \" \"声音\":\"默认\&#34 ;, \"徽章\":2}}&#34 ;;
它完全被客户端接收。但是,当我用一些印地语数据代替" 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)
印地语文本收到?????
答案 0 :(得分:0)
试试这段代码,对我来说很好.. 已完成的更改
写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();
}
}