如何使用 java 库将类别键添加到推送通知

How to add category key to push notifications using java library

当我尝试这样添加时,类别键出现在 aps 字典之外。请帮我在 aps 字典中添加类别关键字。 我试过下面的代码

payload.addCustomDictionary("category", "Alerts");

我认为您在这里指的是 JAVAPNS。据我所知,'Payload' class 没有 'category' 的占位符。

addCustomDictionary 将在 'aps'

之外添加

您必须使用一些变通方法将 'aps' 键与 'category' 组合起来。 (例如如下)

JSONObject temp = new JSONObject();
temp.put("category", "alert");
JSONObject myPayload = new JSONObject();
myPayload.put("aps", temp);

希望对您有所帮助。

在最新版本的Javapns Jdk16中,增加了addCategory字段。

参考文献:

https://mvnrepository.com/artifact/com.github.fernandospr/javapns-jdk16/2.4.0

https://github.com/fernandospr/javapns-jdk16