【问题标题】:AppCenter: How to retrieve the `name` property of `notification_content` object in Xamarin?AppCenter:如何在 Xamarin 中检索“notification_content”对象的“name”属性?
【发布时间】:2020-02-01 20:55:45
【问题描述】:

我正在查看documentation 使用 AppCenter 发送推送通知。我能够成功创建和发送推送通知,但我不明白为什么我们需要 notification_content 对象中的 name 属性。是必需的吗?谁使用它?

我问的原因是我想根据类型过滤客户端设备上的通知。我希望为此目的使用name 属性,而不是在custom_data 中创建另一个属性。

在 Android 上,我可以像这样检索通知标题和文本:

var title = statusBarNotification.Notification.Extras.GetString("android.title");
var text = statusBarNotification.Notification.Extras.GetString("android.text");

还有没有办法检索name 属性?

【问题讨论】:

    标签: android xamarin push-notification visual-studio-app-center


    【解决方案1】:

    首先无法从通知中接收name 属性,您无法从通知数据中检索它,如下图所示。

    Second该属性仅用于App Center显示在通知列表中,并没有从App Center中寻找方法来检索它。

    Send Notification document 开始,name 属性用于定义通知消息的名称,如下所示。

    {
      "notification_content": {
        "name": "First Push From App Center",
        "title": "Push From App Center",
        "body": "Hello! Isn't this an amazing notification message?",
        "custom_data": {"key1": "val1", "key2": "val2"}
      }
    }
    
    • name:定义通知消息的名称。

    如果您在 App Center 中查看 this document 关于在不使用 API 的情况下发送通知,您将看到 Campaign Name 是 API 中的 name 属性。

    使用广告系列的描述性名称填充 广告系列名称 字段。您提供的值将显示在 App Center 广告系列列表页面中。

    它只是显示在 App Center 列表页面中,但是我也找不到其他 api 来在 App Center 中获取此属性。

    因此,如果我们无法从 Notification Data 甚至 App Center 中检索到它,那么我建议您使用 custom_data 来自定义您需要的数据。 p>

    【讨论】:

    • 谢谢。我也以为name被AppCenter使用了,但是文档没有说清楚。
    • @user246392 是的,没错。 api 的文档没有对此进行更多解释。我们可以从 App Center 中 url 的doc 知道。
    猜你喜欢
    • 2016-03-08
    • 1970-01-01
    • 2012-09-13
    • 2017-07-11
    • 2017-05-18
    • 1970-01-01
    • 2020-04-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多