我对如何使用PushSharp构建GCM推送通知的消息体感到有点困惑。GitHub代码库中的文档和测试文件显示了如下所示的消息结构:
broker.QueueNotification (new GcmNotification {
RegistrationIds = new List<string> {
regId
},
Data = JObject.Parse ("{ \"somekey\" : \"somevalue\" }")
});我一直在使用Postman进行测试,在该测试中,我将以下JSON格式的消息发送到https://gcm-http.googleapis.com/gcm/send。
{
"to": "000-0000-mytoken-foo",
"notification" : {
"title" : "Push Test Notification",
"body" : "GCM Test Push",
"icon" : "icon",
"color" : "#FF4081"
}
}框架是否已经处理了消息的'to'和'notification'部分?根据我所看到的示例,似乎我只需要输入通知对象的键:值对,但我似乎找不到文档中声明的位置或实际消息的示例。我使用的是PushSharp的最新版本(4.x)。
发布于 2016-12-01 22:34:10
嗨,你可以这样走。
var config = new GcmConfiguration("senderKey", "apiKey", null);
config.GcmUrl = "https://fcm.googleapis.com/fcm/send"; //!!!!!gmc changed to fcm;)
var gcmBroker = new GcmServiceBroker(config);
gcmBroker.Start();
_gcmBroker.QueueNotification(new GcmNotification
{
RegistrationIds = new List<string> { "YourDeviceToken" },
Notification = JObject.Parse(
"{" +
"\"title\" : \"" + yourMessageTitle + "\"," +
"\"body\" : \"" + yourMessageBody + "\"," +
"\"sound\" : \"mySound.caf\"" +
"}") ,
Data = JObject.Parse(
"{" +
"\"CustomDataKey1\" : \"" + yourCustomDataValue1 + "\"," +
"\"CustomDataKey2\" : \"" + yourCustomDataValue2 + "\"" +
"}")
});我没有测试自定义数据值是否到达,但通知是:)以" your“开头的项是您的动态参数,如传递给该方法的参数等。这个问题很久以前就提出了,但我现在才开始使用pushsharp:)希望这对PushSharp用户有帮助。
https://stackoverflow.com/questions/36905361
复制相似问题