Push message doesn't send using with distributed certificate

匿名 (未验证) 提交于 2019-12-03 02:38:01

问题:

I can send push notification with developer p12 file using with sandbox, but my application on the appstore, I use distribution certificate f12 file using with gateway.push.apple.com messages cannot reach to devices.

Push notification service activated on distirbuted certificate, I checked on developer.apple.com, I'm also trying new device id. (not developer device id)

How can i solve my problem? Could you help me? where is my wrong?

My C# code like below:

int port = 2195;

    String hostname = "gateway.push.apple.com";      String certificatePath = HttpContext.Current.Server.MapPath("distribution.p12");       X509Certificate2 clientCertificate = new X509Certificate2(System.IO.File.ReadAllBytes(certificatePath), "xxx", 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, true);     }     catch (Exception e)     {         throw (e);         client.Close();         return;     }     MemoryStream memoryStream = new MemoryStream();     BinaryWriter writer = new BinaryWriter(memoryStream);     writer.Write((byte)0);      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)     //String deviceID = "f1430c99 910d292d 2f756294 f2f6b348 153bc215 d5404447 16b294eb fdb9496c";     writer.Write(HexStringToByteArray(deviceID.ToUpper()));     String payload = "{\"aps\":{\"alert\":\"" + Mesaj + "\",\"badge\":0,\"sound\":\"default\"}}";     writer.Write((byte)0);     writer.Write((byte)payload.Length);     byte[] b1 = System.Text.Encoding.UTF8.GetBytes(payload);     writer.Write(b1);     writer.Flush();     byte[] array = memoryStream.ToArray();     sslStream.Write(array);     sslStream.Flush();     client.Close(); 
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!