【问题标题】:Azure Hub notification cannot send to FCMAzure Hub 通知无法发送到 FCM
【发布时间】:2017-08-07 14:37:25
【问题描述】:

当来源是 Azure 时,我通过 Azure 通知中心接收通知时遇到问题。我按照本教程的步骤进行操作: https://developer.xamarin.com/guides/android/application_fundamentals/notifications/remote-notifications-with-fcm/

此时,在出现一些 nuget 依赖冲突问题后,我通过 Firebase 控制台正确收到了通知。但是,Azure 通知中心的“测试发送”选项似乎发送了消息,但设备没有收到通知。

按照其他教程使用 FCM 服务发送 Azure 通知 https://docs.microsoft.com/en-us/azure/notification-hubs/notification-hubs-android-push-notification-google-fcm-get-started,某些步骤在 Xamarin.Android 中似乎无法实现,例如在 build.gradle 中添加依赖项。

如何将这些更改合并到 Xamarin.Android 项目中?

【问题讨论】:

    标签: azure xamarin notifications xamarin.android azure-notificationhub


    【解决方案1】:

    杰拉德,

    从 Firebase 控制台和 Azure 通知中心的“测试发送”选项发送消息时,获取消息内容的方式不同。

    正如您在Xamarin turorial with FCM 中看到的,要获取消息内容,我们执行以下操作:

    public override void OnMessageReceived(RemoteMessage message)
    {
        Log.Debug(TAG, "From: " + message.From);
        Log.Debug(TAG, "Notification Message Body: " + message.GetNotification().Body);
    }
    

    但是在使用测试发送时它不起作用,因为GetNotification() 将为空。

    使用测试发送时,我们发送以下有效负载:

    {"data":{"message":"Notification Hub test notification"}}
    

    现在如何获取您的消息?如果您查看RemoteMessage,您会注意到以下Data 属性:public IDictionary<string, string> Data { get; }

    您将能够使用Data 属性检索您的消息,如下所示:

    public override void OnMessageReceived(RemoteMessage remoteMessage)
    {
        Log.Debug(TAG, "From: " + remoteMessage.From);
    
        if (remoteMessage.Data.ContainsKey("message"))
        {
            Log.Debug(TAG, "Notification Message: " + remoteMessage.Data["message"]);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2021-02-11
      • 2018-03-22
      • 1970-01-01
      • 1970-01-01
      • 2017-01-17
      • 2021-10-17
      • 2019-07-21
      • 2017-02-27
      • 1970-01-01
      相关资源
      最近更新 更多