如何在Azure Notification Hub中使用具有多个自定义属性的推送通知模板?

The*_*eaf 4 azure push-notification azure-notificationhub

我们正在学习本教程:如何:适用于Android的Windows Azure通知中心(Android应用程序).

在构建通知有效负载时,一切正常,如指南中所述.那是:

{
    "data": {
        "msg": "$(property1)"
    }
}
Run Code Online (Sandbox Code Playgroud)

但是,我们希望扩展模板以在有效负载中使用多个自定义属性.就像是:

{
  "data": {
    "msg": {
        "message": "$(property1)",
        "sender": "$(property2)"
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

后端通过以下方式提供属性值:

Dictionary<string, string> templateValues = new Dictionary<string, string>
    {
        { "property1", "Hello world" },
        { "property2", "foo" }
    };

NotificationOutcome notificationOutcome = await Hub.SendTemplateNotificationAsync(templateValues, "test");
Run Code Online (Sandbox Code Playgroud)

从移动应用程序在通知中心注册模板时,我们收到以下错误:

"提供的通知有效负载无效"

  • 可以在模板中使用多个属性吗?
  • 我们应该将属性值(来自后端)作为JSON(或其他结构)字符串发送吗?什么是首选方法?我们将在多个平台上使用该模板(iOS,Android)

提前致谢

小智 6

有效内容无效,因为GCM不支持数据成员中的嵌套对象.您可以通过注册以下模板来发送带有两个属性的消息:

{
   "data": {
      "message": "$(property1)",
      "sender": "$(property2)"
   }
}
Run Code Online (Sandbox Code Playgroud)

在你的Android接收器中,你可以检索你的属性

intent.getStringExtra("property1");
Run Code Online (Sandbox Code Playgroud)