Skip to content

Instantly share code, notes, and snippets.

@felipebaltazar
Created March 2, 2021 01:41
Show Gist options
  • Save felipebaltazar/f871440d05d4206a376f594dd9770cda to your computer and use it in GitHub Desktop.
Save felipebaltazar/f871440d05d4206a376f594dd9770cda to your computer and use it in GitHub Desktop.
public class PushDelegate : IPushDelegate
{
private readonly Lazy<INotificationManager> _notificationManager;
public PushDelegate(Lazy<INotificationManager> notificationManager)
{
_notificationManager = notificationManager;
}
public async Task OnEntry(PushEntryArgs args)
{
}
public async Task OnReceived(IDictionary<string, string> data)
{
// Verificamos se existe a propriedade no json, para mostrar ou nao a notificacao
var showNotification = false;
if (data.ContainsKey("show_notification"))
{
_ = bool.TryParse(data["show_notification"], out showNotification);
}
var title = "default notification title";
var message = "default notification message";
// Podemos ter dados mais complexos e deserializar eles, caso necessário
if (data.ContainsKey("title"))
title = data["title"];
if (data.ContainsKey("title"))
message = data["message"];
var notification = new Notification
{
Title = title,
Message = message,
Payload = data?.ToDictionary(
x => x.Key,
x => x.Value
)
};
await _notificationManager.Value.Send(notification);
}
public Task OnTokenChanged(string token)
{
return Task.CompletedTask;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment