Для отправки массового уведомления в pushsharp, я использую foreach loop. Я получаю несколько обратных вызовов для одного уведомления.Несколько обратных вызовов для одного уведомления Pushsharp
Предположим, что я отправил уведомление на 3 устройства, я получаю обратный вызов 10 раз. Он повторяет уведомление об обратном вызове для всех 3 устройств.
foreach (var recipient in recipients)
{
//Wire up the events for all the services that the broker registers
push.OnChannelCreated += push_OnChannelCreated;
push.OnChannelDestroyed += push_OnChannelDestroyed;
push.OnChannelException += push_OnChannelException;
push.OnDeviceSubscriptionChanged += push_OnDeviceSubscriptionChanged;
push.OnDeviceSubscriptionExpired += push_OnDeviceSubscriptionExpired;
push.OnNotificationFailed += push_OnNotificationFailed;
push.OnNotificationRequeue += push_OnNotificationRequeue;
push.OnNotificationSent += push_OnNotificationSent;
push.OnServiceException += push_OnServiceException;
var gcmMessage = new GCMMessage
{
message = TemplateUtility.GetNotificationBodyGcm(TemplateName, recipient),
badge=7,
sound="sound.caf"
};
string jsonGcmMessage = Newtonsoft.Json.JsonConvert.SerializeObject(gcmMessage);
push.RegisterGcmService(new GcmPushChannelSettings(ConfigurationManager.AppSettings["GCM_Development_ServerKey"].ToString()));
//push.RegisterGcmService(new GcmPushChannelSettings(ConfigurationManager.AppSettings["GCM_Production_ServerKey"].ToString()));
push.QueueNotification(new GcmNotification().ForDeviceRegistrationId(recipient.DeviceRegistrationToken)
//.WithJson("{\"message\":\"Hi PushNoti\",\"badge\":7,\"sound\":\"sound.caf\"}"));
.WithJson(jsonGcmMessage));
//Stop and wait for the queues to drains before it dispose
push.StopAllServices(waitForQueuesToFinish: true);
}