Skip to content

ios - if one DeviceToken are wrong no push are sent #713

Description

@jsundstr

v.4.0.10.0

Problem
If I send a batch of notifications and one of the DeviceToken are wrong the correct ones dont sends,

Try it
send a batch with two DeviceToken one wrong and one correct, and you dont get the correct pushnotification either

Exception
2016-05-31 17:18:14. [DEBUG] Scaled Changed to: 1
2016-05-31 17:18:14. [INFO] Stopping: Waiting on Tasks
2016-05-31 17:18:14. [INFO] Waiting on all tasks 2
2016-05-31 17:18:15. [INFO] APNS-Client[1]: Sending Batch ID=1, Count=2
2016-05-31 17:18:15. [ERROR] APNS-CLIENT[1]: Send Batch Error: Batch ID=1, Error=PushSharp.Core.NotificationException: Invalid DeviceToken
at PushSharp.Apple.ApnsNotification.ToBytes()
at PushSharp.Apple.ApnsConnection.createBatch(List`1 toSend)
at PushSharp.Apple.ApnsConnection.d__21.MoveNext()
2016-05-31 17:18:15. [INFO] APNS-Client[1]: Sent Batch, waiting for possible response...
2016-05-31 17:18:15. [ERROR] APNS-Client[1]: Reader Exception: System.NullReferenceException: Object reference not set to an instance of an object.
at PushSharp.Apple.ApnsConnection.d__23.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at PushSharp.Apple.ApnsConnection.d__21.MoveNext()
2016-05-31 17:18:15. [INFO] APNS-Client[1]: Done Reading for Batch ID=1, reseting batch timer...
Apple Notification Failed: ID=1, Code=ConnectionError
Apple Notification Failed: ID=2, Code=ConnectionError
2016-05-31 17:18:15. [INFO] All Tasks Finished
2016-05-31 17:18:15. [INFO] Passed WhenAll
2016-05-31 17:18:15. [INFO] Broker IsCompleted
2016-05-31 17:18:15. [DEBUG] Broker Task Ended
2016-05-31 17:18:15. [INFO] Stopping: Done Waiting on Tasks

Code
// Wire up events
apnsBroker.OnNotificationFailed += (notification, aggregateEx) =>
{
string error = string.Empty;
aggregateEx.Handle(ex =>
{

                            //See what kind of exception it was to further diagnose
                            if (ex is ApnsNotificationException)
                            {
                                var notificationException = (ApnsNotificationException)ex;

                                //Deal with the failed notification
                                var apnsNotification = notificationException.Notification;
                                var statusCode = notificationException.ErrorStatusCode;

                                error = $"Apple Notification Failed: ID={apnsNotification.Identifier}, Code={statusCode}";
                                upd_failed(notification, error);
                                Console.WriteLine(error);

                            }
                            else
                            {
                                //Inner exception might hold more useful information like an ApnsConnectionException 
                                error = $"Apple Notification Failed for some unknown reason : {ex.InnerException}";
                                upd_failed(notification, error);
                                Console.WriteLine(error);
                            }

                            // Mark it as handled
                            return true;
                        });
                    };
                    apnsBroker.OnNotificationSucceeded += (notification) =>
                    {
                        Console.WriteLine("Apple Notification Sent!");
                        upd_sent(notification);
                    };


                    // Start the broker
                    apnsBroker.Start();

                foreach (XmlNode node_ios in list_ios)
                {

                        string device_token = node_ios.Attributes.GetNamedItem("device_token").Value;
                        string json = jsonAPNS(node_ios);

                        apnsBroker.QueueNotification(new ApnsNotification
                        {
                            DeviceToken = device_token,
                            Payload = JObject.Parse(json)
                        });

                }
                    // Stop the broker, wait for it to finish   
                    // This isn't done after every message, but after you're
                    // done with the broker
                    apnsBroker.Stop();

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions