void OnPushNotificationReceived(PushNotificationChannel sender, PushNotificationReceivedEventArgs e) { var pushNotification = new PushNotification(); switch (e.NotificationType) { case PushNotificationType.Badge: pushNotification.Type = "badge"; pushNotification.JsonContent.Add("innerText", e.BadgeNotification.Content.InnerText); break; case PushNotificationType.Tile: pushNotification.Type = "tile"; pushNotification.JsonContent.Add("innerText", e.TileNotification.Content.InnerText); break; case PushNotificationType.Toast: pushNotification.Type = "toast"; pushNotification.JsonContent.Add("innerText", e.ToastNotification.Content.InnerText); break; default: // Do nothing return; } if (this.pushOptions.NotificationCallback != null) { this.ExecuteCallback(this.pushOptions.NotificationCallback, JsonConvert.SerializeObject(pushNotification)); // prevent the notification from being delivered to the UI, expecting the application to show it e.Cancel = true; } else { TryExecuteErrorCallback("PushPlugin.OnPushNotificationReceived: No push event callback defined"); } }
void PushChannel_ShellToastNotificationReceived(object sender, NotificationEventArgs e) { Dictionary <string, object> content = new Dictionary <string, object>(); PushNotification toast = new PushNotification { Type = "toast", Content = content }; foreach (var item in e.Collection) { if (item.Key == "wp:Data") { content.Add(item.Key, JsonConvert.DeserializeObject <dynamic>(item.Value)); } else { content.Add(item.Key, item.Value); } } SendEvent(JsonConvert.SerializeObject(toast)); }
private void PushChannel_ShellToastNotificationReceived(object sender, NotificationEventArgs e) { var toast = new PushNotification { Type = "toast" }; toast.JsonContent = new ExpandoObject(); foreach (var item in e.Collection) { toast.JsonContent.Add(item.Key, item.Value); } this.ExecuteCallback(JValue.FromObject(toast).ToString()); }
private void PushChannel_HttpNotificationReceived(object sender, HttpNotificationEventArgs e) { var raw = new PushNotification { Type = "raw" }; raw.JsonContent = new ExpandoObject(); using (var reader = new StreamReader(e.Notification.Body)) { raw.JsonContent.Add("Body", reader.ReadToEnd()); } this.ExecuteCallback(JValue.FromObject(raw).ToString()); }