public void Send(NotificationPayload notification, IDevice device) { if (string.IsNullOrEmpty(device.Token)) { return; } // Configuration (NOTE: .pfx can also be used here) ApnsConfiguration config = new ApnsConfiguration(ApnsConfiguration.ApnsServerEnvironment.Production, certificatePath, certificatePassword); IOSNotification payload = new IOSNotification(notification); ApnsNotification apnsNotification = new ApnsNotification { DeviceToken = device.Token, Payload = JObject.FromObject(payload) }; Console.WriteLine(apnsNotification.ToString()); ApnsServiceBroker apnsBroker = new ApnsServiceBroker(config); apnsBroker.OnNotificationSucceeded += this.onSuccess; apnsBroker.OnNotificationFailed += this.onFailure; apnsBroker.Start(); apnsBroker.QueueNotification(apnsNotification); apnsBroker.Stop(); }
public void Send(NotificationPayload notification, IEnumerable <IDevice> devices) { ApnsConfiguration config = new ApnsConfiguration(ApnsConfiguration.ApnsServerEnvironment.Production, certificatePath, certificatePassword); IOSNotification payload = new IOSNotification(notification); ApnsServiceBroker apnsBroker = new ApnsServiceBroker(config); apnsBroker.OnNotificationSucceeded += this.onSuccess; apnsBroker.OnNotificationFailed += this.onFailure; apnsBroker.Start(); ApnsNotification apnsNotification = new ApnsNotification { Payload = JObject.FromObject(payload) }; foreach (var device in devices) { apnsNotification.DeviceToken = device.Token; Console.WriteLine(apnsNotification.ToString()); apnsBroker.QueueNotification(apnsNotification); } apnsBroker.Stop(); }