当一个PushSharp消息失败时,它们都会失败

时间:2014-05-16 17:56:10

标签: apple-push-notifications pushsharp

我正在使用Push Sharp库向Apple APN服务器发送推送通知。代码效果很好,我可以发送1000个通知。

问题是,如果我尝试发送带有无效设备令牌的通知,我会收到来自推送框架pushsharp.apple.notificationfailureexception的失败消息,并且在该点之后排队的每条消息都发送。基本上,如果单个通知失败,PushSharp将清除其队列。

例如,如果我排队4个通知(1,2,3,4)并且通知2具有无效的设备令牌,则将发送通知1,2将失败,并且不发送3和4(并且没有事件被解雇通知这个)。

我了解使用无效设备令牌的通知将不会被发送,但不能接受将其他 N 排队通知放在地板上。

这有什么变通方法吗?

这是我的代码:

_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);

1 个答案:

答案 0 :(得分:1)

确定。 this answerthis answer似乎有所帮助。

就像我在测试中发现的那样,当我有一个无效的设备令牌时,我会得到一个OnNotificationFailed事件,并且每个后续的通知也会失败。

简短的说法是Apple似乎无声地删除了无效设备令牌上的连接,然后所有后续操作都失败了(同样的错误)。

一切都不会丢失。在OnNotificationFailed的事件处理程序中,您可以检查传入的通知的内容,以查看哪些失败。

下一个合乎逻辑的步骤是单独行走,重新发送相同的通知。然后将那些因未来通知而无效的第二次失败的修剪和/或标记成功的那些失败。