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.