1

我正在尝试从我的 .Net 服务器向所有下载了我的 Android 应用程序的 Android 设备发送通知。我正在使用 PushSharp 库。发送通知很好。但我试图从 GCM 获得响应,告诉我规范注册 ID 如果用户卸载应用程序并重新下载它。我在向同一个 android 设备发送拖车通知时遇到问题。一个使用新 ID,一个使用未注册 ID 我正在尝试从我的数据库中删除该 ID。这样我只能为单个设备发送一个通知。我会注册这 4 个由 GCM 触发的事件。在哪个事件中我可以做我的逻辑?

任何帮助表示赞赏。

这是我的代码:

    private static void Events_OnNotificationSent(Notification notification)
    {

    }

    private static void Events_OnNotificationSendFailure(Notification notification, Exception notificationFailureException)
    {

    } 



    private static void Events_OnChannelException(Exception exception, PlatformType platformType, Notification notification)
    {
    } 



    private static void Events_OnDeviceSubscriptionExpired(PlatformType platform, string deviceInfo, Notification notification)
    {

    } 



    private static void Events_OnDeviceSubscriptionIdChanged(PlatformType platform, string oldDeviceInfo, string newDeviceInfo, Notification notification)
    {

    }
4

1 回答 1

0

如果我对您的理解正确,如果用户卸载了您的应用程序,您希望从数据库中删除该设备。我正在为我的项目使用以下逻辑:

private void Events_OnNotificationFailed(object sender, INotification notification, Exception error)
{
    var gcmNotification = notification as GcmNotification;
    bool userHasUninstalled = error.Message.Contains("Device Subscription has Expired");
    bool isAndroidNotification = gcmNotification != null;
    if (isAndroidNotification && userHasUninstalled)
    {
        foreach (var registrationId in gcmNotification.RegistrationIds)
        {
            DeleteDeviceByIdentifier(registrationId);
        }
    }
}
于 2013-09-07T19:29:38.447 回答