I use the PushSharp library to send Apple Push notifications. For some reason, the devices only get some notifications that I click. For example, if I click 5 notifications on one device, it can only accept 3. I use 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ām kind of stuck in this - does anyone have any ideas as to what might be causing this?
EDIT 1:
I noticed that I accidentally turned on the development identifiers of some devices. I thought that everything would be alright, as I expected Apple to simply decline these notification requests. Removing these identifiers from the query seems to have made it somewhat more stable. I will continue to monitor this issue, but it seems strange that sending an APN request with a bad device identifier will stop my connection from sending future notifications that I have queued ...
Edit 2:
Firstly, I found that my notifications had to be connected before I made a call to register an Apple service (my code above was changed to reflect the correct way to do this). In addition, I found that APN is designed to stop sending notifications if the first one does not work. I believe PushSharp is trying to resend items that have not been sent, but I will need to do additional testing to make sure this works. At the moment, it seems that sending the identifier of the development device to the production server will cause all notifications to be sent after this happens, using the same PushBroker connection.
source share