Skip to content

Commit 43b4f2e

Browse files
authored
Updated ApnsConnection createBatch
Fixed one ApnsNotification failing validation in ToBytes() causing the whole batch to fail - now triggers CompleteFailed for the notifications that fail validation, skips them and continues to send the rest.
1 parent f68bb1e commit 43b4f2e

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

PushSharp.Apple/ApnsConnection.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.IO;
33
using System.Net.Sockets;
44
using System.Net.Security;
@@ -185,9 +185,20 @@ byte[] createBatch (List<CompletableApnsNotification> toSend)
185185
var batchData = new List<byte> ();
186186

187187
// Add all the frame data
188-
foreach (var n in toSend)
189-
batchData.AddRange (n.Notification.ToBytes ());
190-
188+
foreach (var n in toSend) {
189+
try {
190+
batchData.AddRange(n.Notification.ToBytes ());
191+
} catch (NotificationException ex) {
192+
// If a notification fails validation, simply fail it and skip
193+
Log.Info("APNS-CLIENT[{0}]: Notification failed validation, failing notification {1}. Batch ID={2}, Error={3}", id, n.Notification.Identifier, batchId, ex);
194+
195+
// Raise the failed event for this notification so the caller knows it wasn't sent
196+
n.CompleteFailed(new ApnsNotificationException(ApnsNotificationErrorStatusCode.ConnectionError, n.Notification, ex));
197+
198+
// Keep adding the other notifications to the batch data to send as we still want to send the others (provided they pass validation themselves)
199+
}
200+
}
201+
191202
return batchData.ToArray ();
192203
}
193204

0 commit comments

Comments
 (0)