我正在使用 javapns 向 iOS 设备发送推送通知,通常使用两种方法,即 alert() 和 payload()。使用此功能中的任何一项,我们都可以向 iOS 设备发送推送通知。在这里,我需要传递 json 对象,而不是在这些方法中的任何一个中发送简单的消息。所以请谁能告诉我如何实现这一目标。
问问题
2912 次
2 回答
0
改用Push. payload(........)
方法,它需要Payload
对象。
String rawJSON = "{\"aps\":{\"alert\":\"Message received from Bob\"},\"acme2\":[\"bang\",\"whiz\"]}";
Payload payload = new Payload(rawJSON);
//Or as mentioned in the comments
PushNotificationPayload payload = PushNotificationPayload.fromJSON(rawJSON);
json的例子是
{
"aps" : { "alert" : "Message received from Bob" },
"acme2" : [ "bang", "whiz" ]
}
对于有效载荷 json通知有效载荷
于 2015-02-20T14:13:33.313 回答
0
忽略 APNS.newPayload 如何创建默认有效负载。
像这样创建您的自定义有效负载。
JSONObject requestedData = new JSONObject();
requestedData.put("id", 1);
requestedData.put("firstName", "K");
requestedData.put("lastName", "Joshi");
JSONObject aps = new JSONObject();
aps.put("alert", "KJ sent a message");
JSONObject request = new JSONObject();
request.put("aps", aps);
request.put("requestedData", requestedData);
//Create Payload
String payload = request.toString();
//Push
apnsService.push("deviceid", payload);
于 2017-09-06T02:11:55.683 回答