Redth / PushSharp

A server-side library for sending Push Notifications to iOS (iPhone/iPad APNS), Android (C2DM and GCM - Google Cloud Message), Windows Phone, Windows 8, Amazon, Blackberry, and (soon) FirefoxOS devices!
Other
4.38k stars 1.52k forks source link

Apns notification error: 'ConnectionError' #855

Open BookHsu opened 6 years ago

BookHsu commented 6 years ago

What version of PushSharp are you using?

version 4.0.10.0 using c# console app

Describe your issue:

I have about 240 devices that need to be pushed, But some of them are faulty device tokens, I found a problem, when I use the for-loop to push all the devices, if the push to the wrong device token, the subsequent full device token even if it is correct will appear the same error.

What are the steps required to reproduce this issue?

    public void Send(IEnumerable<UUIDModel> SendDevice, string Title, string MessageContent, int QueueID, string Lang)
     {
        string strCertFile = "FileName";

        var appleCert = File.ReadAllBytes(string.Format("{0}\\cert\\{1}", AppDomain.CurrentDomain.BaseDirectory, strCertFile));
        ApnsConfiguration pushConfig = new ApnsConfiguration(ApnsConfiguration.ApnsServerEnvironment.Production, appleCert, "myPassword");
        ApnsServiceBroker apnsBroker = new ApnsServiceBroker(pushConfig);
        apnsBroker.OnNotificationFailed += NotificationFailed;
        apnsBroker.OnNotificationSucceeded += NotificationSucceeded;
        apnsBroker.Start();
        foreach (var item in SendDevice)
        {
            JObject jObject = JObject.FromObject(new
            {
                aps = new { alert = new { title = Title, body = MessageContent }, sound = "default", badge = 1 }
            });

            apnsBroker.QueueNotification(new ApnsNotification(item.DeviceToken, jObject));
        }
        apnsBroker.Stop();

    }

Please provide any Exception Stack Traces

This is the wrong devicetoken 18:30:12 0.0.0.0 N/A NotificationFailed-APN Token=<36651c38 15054f04 feaa0571 87d52587 f5b62d63 733f68f8 b3d5ee2f 01ac6f8b> 18:30:12 0.0.0.0 N/A NotificationFailed-APN Apns notification error: 'ConnectionError' 18:30:12 0.0.0.0 N/A NotificationFailed-APN Invalid DeviceToken This is the correct device token 18:30:13 0.0.0.0 N/A NotificationFailed-APN Token=3c39c9dd23a8da53077c5ee104276d7372eafaf446f9371f1ece116b1f3c37ee 18:30:13 0.0.0.0 N/A NotificationFailed-APN Apns notification error: 'ConnectionError' 18:30:13 0.0.0.0 N/A NotificationFailed-APN Invalid DeviceToke

If I do a push on a single correct device token, I can normally receive a push message.

sultanwork77 commented 6 years ago

Any update on this. Am also getting same problem. If one device i get ConnectionError then all are falling under that. Even the correct device tokenid its not able to send the notification.

opacitychris commented 6 years ago

I am also getting connection error problems.

1) I confirmed and even re-created my certificates to be safe 2) switched between production and sanbox 3) tried different servers 4) saw some people had TLS related SSL problems and tried some options there

no luck, returns Code=ConnectionError

dickverweij commented 6 years ago

Any update on this? Having the same problems..

opacitychris commented 6 years ago

@dickverweij Yes, I posted on a different git thread about how i resolved.

My solution was found in debugging.

While i got "connection error" as the main error, debugging the exception to the InnerException showed me an Invalid Token error.

My token though was perfectly fine from the phone and I confirmed that it was the right one (production vs sandbox)

However, when stripping the spaces from the token, everything worked.