4

I am using the PushSharp library to send Apple Push Notifications. For some reason, the devices are only getting some of the notifications that I push. For instance, if I push 5 notifications to one device, it may only receive 3. I am using the following code:

while(true)
{
    //... build models...

    PushBroker push = new PushBroker();
    push.OnNotificationFailed += OnNotificationFailed;
    push.OnDeviceSubscriptionExpired += OnDeviceSubscriptionExpired;
    push.OnChannelException += OnChannelException;
    push.OnServiceException += OnServiceException;
    push.OnChannelDestroyed += OnChannelDestroyed;
    push.OnDeviceSubscriptionChanged += OnDeviceSubscriptionChanged;
    push.OnNotificationRequeue += OnNotificationRequeue;
    push.OnNotificationSent += OnNotificationSent;
    push.RegisterAppleService(new ApplePushChannelSettings(true, appleCert, "Password"));

    // Send a notification to each registered device.
    foreach (var model in models)
    {
         _pushBroker.QueueNotification(new AppleNotification()
              .ForDeviceToken(model.DeviceToken)
              .WithAlert(model.alert)
              .WithBadge(models.Count())
              .WithCustomItem("id", model.Id)
              );
     }

     _pushBroker.StopAllServices();

     // Sleep for 15 minutes
     Thread.Sleep(15 * 60000);
}

I am kind of stuck on this one - does anyone have any ideas as to what could be causing this?

EDIT 1:

I did notice that I was accidentally including the development ids of some devices. I had thought that would have been alright, as I would have expected Apple to just reject those notification requests. Removing those ids from the request seems to have made it slightly more stable. I will be continuing to monitor this issue, but it seems strange that sending a request to APN with a bad device id would stop my connection from sending future notifications that I have queued up...

Edit 2:

First, I found that my notifications should have been wired up BEFORE I made the call to register the apple service (my above code has been modified to reflect the correct way to do this). Also, I have found that APN is designed to stop sending notifications if the first one fails. I believe PushSharp tries to resend items that have not been sent, but I will need to do some further testing to verify that this works. For the moment, it seems like sending a development device id to the production server will cause all notifications sent after that one to fail while using the same PushBroker connection.

lehn0058
  • 19,977
  • 15
  • 69
  • 109
  • 1
    Did you find anything else out on this sir? We are having the same problem it appears. Many go through, then suddenly they stop going through. Later they start going through again. The worse part is that the ones that never get through we still are getting a NotificationSent response (which apparently means successful). – Nicholas Petersen Dec 17 '13 at 17:14
  • 1
    @NicholasPetersen My issue was the order of wiring up the event handlers, and that iOS devices have both a development push notification id and a production one for a given app. If you try to send a development device id to the production APN service, the service fails all other requests you have queued. Removing the development push notification device ids resolved this issue for me and I haven't had an issue sending notifications since. – lehn0058 Dec 17 '13 at 17:30
  • @NicholasPetersen also, _pushBroker.StopAllServices() seemed to cause some issues, so I only call that when I am done with the service and have given the system enough time to have sent out the messages. – lehn0058 Dec 17 '13 at 17:33
  • Thanks! I hope you'll post those two comments as an answer. Do you know how to find out if any given id is a development id? Maybe we should just delete our current devices and start over. – Nicholas Petersen Dec 17 '13 at 18:06
  • Also: Are you having to do anything with the 'Feedback Service'? I just discovered it (end of page: https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/CommunicatingWIthAPS.html) As is typical, it looks 1000 times harder than it needs to be, though I noticed PushSharp has this: https://github.com/Redth/PushSharp/blob/dc377567e69c81228dde1f2597a1402f8a3b3489/PushSharp.Apple/FeedbackService.cs. I'm not sure what to do with it. – Nicholas Petersen Dec 17 '13 at 18:08
  • "My issue was the order of wiring up the event handlers" - you mean it matters? that is bizarre. Why in the world would it matter??? And what went wrong with it? I have: this.push = new PushBroker(); push.OnNotificationFailed += push_OnNotificationFailed; ... OnNotificationRequeue, OnNotificationSent, OnServiceException, OnChannelException, OnDeviceSubscriptionChanged, OnDeviceSubscriptionExpired – Nicholas Petersen Dec 17 '13 at 18:14
  • @lehn0058 u pointed me in the right direction..my db has some tokens which were sandbox devices..i havent removed them yet but i think this will help..i must say apple's infra is a big pain in the ass..thanks :) – Lakshay Dulani Mar 02 '17 at 12:54

0 Answers0