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

use*_*999 5 apple-push-notifications pushsharp

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

问题是,如果我尝试发送带有无效设备令牌的通知,我会收到来自push sharp框架的失败消息,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);
Run Code Online (Sandbox Code Playgroud)

BIB*_*IBD 1

好的。这个答案这个答案似乎有帮助。

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

简而言之,苹果似乎默默地断开了无效设备令牌上的连接,然后接下来的一切都失败了(同样的错误)。

一切并没有失去。在 OnNotificationFailed 的事件处理程序中,您可以检查传入的通知内容以查看哪些通知失败。

下一个合乎逻辑的步骤是单独遍历它们,重新发送相同的通知。然后从未来的通知中删除第二次失败的无效通知和/或将成功的通知标记为良好。