【问题标题】:How to use push notification template with several custom properties in Azure Notification Hub?如何在 Azure 通知中心使用具有多个自定义属性的推送通知模板?
【发布时间】:2013-10-11 05:39:24
【问题描述】:

我们正在学习本教程:How To: Windows Azure Notification Hubs (Android Apps) for Android。

按照指南中的描述构建通知负载时,一切正常。那就是:

{
    "data": {
        "msg": "$(property1)"
    }
}

但是,我们希望扩展模板以在负载中使用多个自定义属性。比如:

{
  "data": {
    "msg": {
        "message": "$(property1)",
        "sender": "$(property2)"
    }
  }
}

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

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

NotificationOutcome notificationOutcome = await Hub.SendTemplateNotificationAsync(templateValues, "test");

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

“提供的通知负载无效”

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

提前致谢

【问题讨论】:

    标签: azure push-notification azure-notificationhub


    【解决方案1】:

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

    {
       "data": {
          "message": "$(property1)",
          "sender": "$(property2)"
       }
    }
    

    在您的 Android 接收器中,您可以检索您的财产

    intent.getStringExtra("property1");
    

    【讨论】:

    • 成功了,谢谢!我们认为 GCM 需要 msg,因为所有示例都使用它.. 我们的马虎
    • @Elio 支持三种不同的平台,我是否需要为每个模板平台设置相同数量的属性,或者我可以为每个模板设置不同数量的属性?我读过很多教程,但它们只描述了每个模板平台通用的单个参数(消息)的情况。
    • 嗨,有谁能帮我解决这个问题。请提供示例如何使用带有模板的 android 进行注册,以及如何从服务器发送有效负载。在过去的几天里,我一直在为同样的问题而苦苦挣扎。提前致谢
    【解决方案2】:

    在我的测试中,你可以添加你的参数:

    模板:

    {
       "data": {
          "message": "$(property1)",
          "args": "$(property2)",
          "myargs": "$(property3)",
       }
    }
    

    数据:

    {  
        "property1":"Jonh",    
        "property2":"1,1",
        "property3":"0",
    }
    

    结果:

    intent.Extras.GetString("message");
    intent.Extras.GetString("args");
    intent.Extras.GetString("myargs");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-05
      • 2021-08-03
      • 1970-01-01
      • 2019-08-25
      • 1970-01-01
      • 2016-12-11
      • 2018-04-28
      • 1970-01-01
      相关资源
      最近更新 更多