0

我使用 PushSharp 发送推送通知。如 GitHub 上的 Redth 文档中所述,我在接收委托方法中的响应时遇到问题。

因此,在我发送特定消息的 10 个 GCM 注册 ID 中,我只收到 9 个响应。我需要这种响应以确保在返回规范 ID 的情况下我应该能够相应地更新我的数据库。

这种行为是设计使然(即不等待来自 GCM 的所有响应)导致很少有响应被丢弃吗?

下面是我的代码片段,以便更好地理解

//创建我们的推送服务代理

    //Create our push services broker
    var broker = new PushBroker();
    broker.OnNotificationSent += new NotificationSentDelegate(NotificationSent);
    broker.OnNotificationFailed += new    PushSharp.Core.NotificationFailedDelegate(NotificationFailed);

    broker.OnChannelException += new ChannelExceptionDelegate(ChannelException);
    broker.OnServiceException += new ServiceExceptionDelegate(ServiceException);

    broker.OnDeviceSubscriptionChanged += new DeviceSubscriptionChangedDelegate(DeviceSubscriptionChanged);
    broker.OnDeviceSubscriptionExpired += new PushSharp.Core.DeviceSubscriptionExpiredDelegate(DeviceSubscriptionExpired);

    broker.OnChannelCreated += new ChannelCreatedDelegate(ChannelCreated);
    broker.OnChannelDestroyed += new ChannelDestroyedDelegate(ChannelDestroyed);

    //---------------------------
    // ANDROID GCM NOTIFICATIONS
    //---------------------------
    broker.RegisterGcmService(new GcmPushChannelSettings(senderID, senderAuthToken, applicationIdPackageName));

    GcmNotification gcm = new GcmNotification();
    gcm.RegistrationIds.Add(deviceRegistrationId1);
    gcm.RegistrationIds.Add(deviceRegistrationId2);
    //and so on

    gcm.WithJson("{\"Test\":\"" + notificationMsg + "\",\"badge\":7,\"sound\":\"sound.caf\"}");

    //Stop and wait for the queues to drains
    broker.StopAllServices(true);

//<

如果我在这个实现中遗漏了什么,请告知。提前致谢

4

1 回答 1

0

当您将委托与 PushSharp 委托而不是您自己的委托关联时,您没有注册以查看失败的通知:

 broker.OnNotificationFailed += new    PushSharp.Core.NotificationFailedDelegate(NotificationFailed);

应该匹配你的:

 broker.OnNotificationSent += new NotificationSentDelegate(NotificationSent);
于 2014-07-07T11:12:28.387 回答