0

我是 Push Sharp 的新手。我正在尝试使用 Push Sharp 向 Android 设备发送消息。它工作得很好,但问题是 Push Sharp 一次又一次地发送相同的消息。

我的代码是:

AndroidPushBroker = new PushBroker();

var googleKey = CustomConfigurationManager.GetValueFromSection("appSettings", "GoogleServerAccessKey");
            AndroidPushBroker.RegisterGcmService(new PushSharp.Android.GcmPushChannelSettings(googleKey));

            var jsonMessage = "{\"InformationId\":\"" + notification.Message + "\",\"badge\":7,\"sound\":\"sound.caf\",\"NotificationType\":\"" + notification.Type.ToString() + "\"}";

            GcmNotification androidNotifcation = new GcmNotification().ForDeviceRegistrationId(notification.DeviceId)
                .WithJson(jsonMessage);
            AndroidPushBroker.QueueNotification(androidNotifcation);

问题:当我发送消息“消息 1”然后发送“消息 2”时,它再次发送“消息 1”。我需要从 Queue 中删除项目吗?或者我错过了什么。?

注意:我的应用程序中有单个 Push Broker 实例。

4

2 回答 2

0

我对 PushSharp 也不是很有经验,但我的猜测是您在发送消息后并没有清空通知队列。

尝试在 QueueNotification 调用之后添加以下内容

AndroidPushBroker.StopAllServices();
于 2014-08-11T08:35:00.590 回答
0

最后我得到了这个问题。我一次又一次地注册我的 gcm 服务,这导致了重复事件。

AndroidPushBroker.RegisterGcmService(new PushSharp.Android.GcmPushChannelSettings(googleKey));

这应该只调用一次。

于 2014-10-02T05:54:12.273 回答