Ik probeer met behulp van de APNs-Sharp library notificaties te pushen naar Apple Push Notification Service, dit is mij gelukt. Echter kan een notification object zover ik zie maar 1 device token bevatten en dus naar slechts 1 device verstuurd worden. Dit leidt er toe dat ik voor elk device een apart notification object aan moet maken en hier doorheen moet loopen met een thread sleep van 1 seconde tussen elke verstuurde notificatie (zodat Apple het niet markeert als flooding).
Het moet echter mogelijk zijn dezelfde notification te versturen aan meerdere devices door gewoon een lijst met devices op te geven. Mij lijkt echter dat dat niet gaat lukken met het standaard Notification object van APNs-Sharp, aangezien die slechts een enkele string heeft voor het device token (geen collectie oid).
Dit is de code die ik momenteel gebruik om berichten te versturen:
Het moet echter mogelijk zijn dezelfde notification te versturen aan meerdere devices door gewoon een lijst met devices op te geven. Mij lijkt echter dat dat niet gaat lukken met het standaard Notification object van APNs-Sharp, aangezien die slechts een enkele string heeft voor het device token (geen collectie oid).
Dit is de code die ik momenteel gebruik om berichten te versturen:
C#:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
| /// <summary> /// Sends a simple message consisting of a simple message body to one or multiple devices. /// </summary> /// <param name="notifications">Notification that needs to be sent, it should include the /// device token. Use ApnsNotification instead of Notification for unit testing purposes.</param> /// <param name="messageBody">The message that needs to be sent.</param> public void SendMessage(IEnumerable<ApnsNotification> notifications, string messageBody) { if (notifications != null) { foreach (ApnsNotification notification in notifications) { notification.Payload.Alert.Body = messageBody; // Check if there is a device token and message and queue the notification. if (!string.IsNullOrEmpty(notification.DeviceToken) && !string.IsNullOrEmpty(messageBody) && _service.QueueNotification(notification)) { notification.MessageQueued = true; if (log.IsDebugEnabled) log.Debug("Notification queued '" + notification + "'."); } else { notification.MessageQueued = false; if (log.IsDebugEnabled) log.Error("Notification failed to be queued."); } // Temporary fix to stop Apple from blocking our messages as a result of 'flooding' Thread.Sleep(1000); } } } |