Ios does not receive push Notifications

Asked

Viewed 143 times

0

The problem is, in my app the server sends Notifications to users but I don’t know why the devices aren’t receiving notifications.

What I’ve already tested:

Server side sends notifications smoothly (active and correct certificates) and correct and active tokenID on the device.

I used the APN Tester Free app to test sending notifications in Production with the same certificate and in this case it sends and devices receive notifications.

What could be wrong to not be able to receive notifications?

  • 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.

  • @Neuberoliveira, as I check the response of the apns?

  • 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.

  • 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

  • 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

  • @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?

  • I’m sorry but I don’t know anything about C, but I think the way is to really test other libs.

  • @Neuberoliveira worth, and does not know indicate other libs?

  • No one can help me with that?

  • i don’t work with C# the most I could do is post a code in PHP that I used

  • @Neuberoliveira, Pena, I do not know how to take this problem off. Thanks anyway.

Show 6 more comments

1 answer

1


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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.