I'm using the Push Sharp library to send push notifications to the Apple APN server. The code works great, I can send 1000s of notifications.
The problem is, if I attempt to send a notification with an invalid device token I receive a failure message from the push sharp framework pushsharp.apple.notificationfailureexception
and every message queued after that point is not sent. Basically, PushSharp clears its queue if a single notification fails.
For example, if I queue 4 notifications (1,2,3,4) and notification 2 has an invalid device token, notification 1 will be sent, 2 will fail, and 3 and 4 are not sent (and no event is fired informing of this).
I understand that the notification with the invalid device token will not be sent but its not acceptable to drop the other N queued notifications on the floor.
Are there any workarounds for this?
Here's my code:
_appleSettings = new ApplePushChannelSettings(!NOTIFICATION_SERVICE_USE_DEVELOPMENT,
NOTIFICATION_SERVICE_USE_DEVELOPMENT
? SSL_CERTIFICATE_NAME_DEV : SSL_CERTIFICATE_NAME_PROD,
SSL_CERTIFICATE_PASSWORD);
_appleSettings.ConnectionTimeout = NOTIFICATION_SERVICE_CONNECTION_TIMEOUT;
_appleSettings.FeedbackIntervalMinutes = 0; /*WE WILL HANDLE THE FEEDBACK EXTERNALLY*/
_appleSettings.MaxConnectionAttempts = NOTIFICATION_SERVICE_RETRY_ATTEMPS;
_serviceSettings = new PushServiceSettings();
_serviceSettings.MaxAutoScaleChannels = NOTIFICATION_SERVICE_NUM_CONNECTIONS;
_pushBroker = new PushBroker();
_pushBroker.OnChannelCreated += _pushBroker_OnChannelCreated;
_pushBroker.OnChannelDestroyed += _pushBroker_OnChannelDestroyed;
_pushBroker.OnChannelException += _pushBroker_OnChannelException;
_pushBroker.OnDeviceSubscriptionChanged += _pushBroker_OnDeviceSubscriptionChanged;
_pushBroker.OnDeviceSubscriptionExpired += _pushBroker_OnDeviceSubscriptionExpired;
_pushBroker.OnNotificationFailed += _pushBroker_OnNotificationFailed;
_pushBroker.OnNotificationRequeue += _pushBroker_OnNotificationRequeue;
_pushBroker.OnNotificationSent += _pushBroker_OnNotificationSent;
_pushBroker.OnServiceException += _pushBroker_OnServiceException;
//now add those settings to the push broker
_pushBroker.RegisterAppleService(_appleSettings, _serviceSettings);
notification = new AppleNotification(notificationMessage.DeviceExtContext);
notification.Payload.Alert.Body = notificationMessage.Message;
notification.Payload.Sound = NOTIFICATION_SOUND;
// notification.Payload.Badge = 1;
notification.Tag = notificationMessage;
//attempt to queue the notification
_pushBroker.QueueNotification(notification);