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, IDevice device) { // Configuration var config = new GcmConfiguration(senderId, authToken, packageName); // Make the broker use Firebase config.GcmUrl = "https://fcm.googleapis.com/fcm/send"; // Create a new broker var gcmBroker = new GcmServiceBroker(config); // Wire up events gcmBroker.OnNotificationFailed += onFailure; gcmBroker.OnNotificationSucceeded += onSuccess; var payload = new AndroidNotification(notification); // Start the broker gcmBroker.Start(); // Queue a notification to send gcmBroker.QueueNotification(new GcmNotification { To = device.Token, Data = JObject.FromObject(payload) }); // Stop the broker, wait for it to finish // This isn't done after every message, but after you're // done with the broker gcmBroker.Stop(); }
public IOSNotification(NotificationPayload notification) { IOSAlert alert = new IOSAlert() { Title = notification.Title, LaunchImage = notification.Image, Body = notification.Message }; ApsNotification aps = new ApsNotification() { Alert = alert, Sound = string.IsNullOrEmpty(notification.Sound) ? ApsNotification.DEFAULT_SOUND : notification.Sound }; this.Aps = aps; var info = GenerateInfo(notification); if (info != null) { this.Info = info; } // Set the aps category string category = Category(notification.Action); if (!string.IsNullOrEmpty(category)) { this.Aps.Category = category; } }
public AndroidNotification(NotificationPayload payload) { Title = payload.Title; Body = payload.Message; Sound = payload.Sound; ClickAction = payload.Action; Icon = payload.Image; Info = GenerateInfo(payload); }
private Dictionary <string, object> GenerateInfo(NotificationPayload payload) { Dictionary <string, object> info = new Dictionary <string, object>(); if (payload.ObjectId != 0) { info.Add("objectId", payload.ObjectId); } return(info.Count > 0 ? info : null); }
/// <summary> /// Send a notification to each device in the list. /// </summary> /// <param name="notification">The notification to send.</param> /// <param name="devices">The list of devices to which send the notification.</param> public void Send(INotification notification, IEnumerable <IDevice> devices) { NotificationBuildersFactory buildersFactory = NotificationBuildersFactory.Instance; INotificationBuilder builder = buildersFactory.Create(notification.Builder); NotificationPayload payload = builder.Build(notification); INotificationService notificationService; foreach (IDevice device in devices) { notificationService = NotificationServiceFactory.Make(device.Type, certificatePath, certificatePassword, senderId, senderAuthToken); if (notificationService != null) { notificationService.Send(payload, device); device.Notified(notification); } } }
public void Send(NotificationPayload notification, IEnumerable <IDevice> devices) { // Configuration var config = new GcmConfiguration(senderId, authToken, packageName); // Make the broker use Firebase config.GcmUrl = "https://fcm.googleapis.com/fcm/send"; // Create a new broker var gcmBroker = new GcmServiceBroker(config); // Wire up events gcmBroker.OnNotificationFailed += onFailure; gcmBroker.OnNotificationSucceeded += onSuccess; var payload = new AndroidNotification(notification); // Make chuncks of 1000 devices that is the max quote supported var chuncks = devices.ToList().ChunkBy(1000); // Start the broker gcmBroker.Start(); foreach (var chunck in chuncks) { // Queue a notification to send gcmBroker.QueueNotification(new GcmNotification { RegistrationIds = devices.Select(d => d.Token).ToList <string>(), Data = JObject.FromObject(payload) }); } // Stop the broker, wait for it to finish // This isn't done after every message, but after you're // done with the broker gcmBroker.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(); }