我正在使用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);