Try that code in C#:
public static void EnviarNotificacaoPush(string tokeDispositivo, string mensagem, string caminhoCertificado, string senhaCertificado)
{
using (var certificado = new X509Certificate2(File.ReadAllBytes(caminhoCertificado), senhaCertificado))
{
var enderecoPushApple = certificado.FriendlyName.StartsWith("Apple Development") ? "gateway.sandbox.push.apple.com" : "gateway.push.apple.com";
using (var clientTcp = new TcpClient(enderecoPushApple, 2195))
{
using (var sslStream = new SslStream(clientTcp.GetStream()))
{
sslStream.AuthenticateAsClient(enderecoPushApple, new X509Certificate2Collection(certificado), SslProtocols.Default, false);
using (var memoryStream = new MemoryStream())
{
using (var writer = new BinaryWriter(memoryStream))
{
var payload = JsonConvert.SerializeObject(new { aps = new { alert = mensagem } });
writer.Write(new byte[] { 0, 0, 32 }.Concat(HexToData(tokeDispositivo)).Concat(new byte[] { 0, (byte)payload.Length }).ToArray());
writer.Write(payload.ToCharArray());
writer.Flush();
sslStream.Write(memoryStream.ToArray());
sslStream.Flush();
}
}
}
}
}
}
private static byte[] HexToData(string hexString)
{
if (hexString.Length % 2 == 1)
hexString = '0' + hexString;
var data = new byte[hexString.Length / 2];
for (int i = 0; i < data.Length; i++)
data[i] = Convert.ToByte(hexString.Substring(i * 2, 2), 16);
return data;
}
When I had trouble with this was certified, I was sending the push with development certificate to the app that was already published in the store, in production. If you put a snippet of the code that makes the sending, check the answer of the apns.
– Neuber Oliveira
@Neuberoliveira, as I check the response of the apns?
– HideCode
In the case I did in php with stream_socket_*, I have no code now, but if I’m not mistaken it is only read the stream with fgets and company.
– Neuber Oliveira
I am programming in C# and call an Apple library and the method I use is as follows: Notificationpayload payload = new Notificationpayload(device,message); List<Notificationpayload> payLoadsList = new List<Notificationpayload> { payload };Pushnotification pushNotification = new Pushnotification(false, path, password); List<String> result = pushNotification.Sendtoapple(payLoadsList);; it should return the token and yet comes to zero
– HideCode
If you’re working on APN Tester Free, I think it might be this lib you’re using, try it with another lib, or maybe do some tests "at hand", maybe even with Curl to do
– Neuber Oliveira
@Neuberoliveira, thanks Pea tip I’m really using a lib that is Moonapns that is already a little old, I have to go look for newer versions and that are compatible with the framework 4.0 that the most current of them is not. Or you have any that can make the turn of this lib?
– HideCode
I’m sorry but I don’t know anything about C, but I think the way is to really test other libs.
– Neuber Oliveira
@Neuberoliveira worth, and does not know indicate other libs?
– HideCode
No one can help me with that?
– HideCode
i don’t work with C# the most I could do is post a code in PHP that I used
– Neuber Oliveira
@Neuberoliveira, Pena, I do not know how to take this problem off. Thanks anyway.
– HideCode