0
爲了在pushsharp中發送批量通知,我使用了foreach循環。 我正在爲同一通知收到多個回叫。一個通知的多個回調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);
}