在PushSharp 4.0中构建GCM消息

我有点困惑的是我应该如何构建使用PushSharp的GCM推送通知的消息体。 GitHub仓库中的文档和测试文件显示了看起来像消息结构的内容:

broker.QueueNotification (new GcmNotification { RegistrationIds = new List { 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)。

你好,你可以这样

 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 { "YourDeviceToken" }, Notification = JObject.Parse( "{" + "\"title\" : \"" + yourMessageTitle + "\"," + "\"body\" : \"" + yourMessageBody + "\"," + "\"sound\" : \"mySound.caf\"" + "}") , Data = JObject.Parse( "{" + "\"CustomDataKey1\" : \"" + yourCustomDataValue1 + "\"," + "\"CustomDataKey2\" : \"" + yourCustomDataValue2 + "\"" + "}") }); 

我没有测试自定义数据值是否到达但是通知确实:)项目以“你的”开头是你的动态参数,比如你传递给那个方法的参数等。很久以前问的问题但我开始使用pushsharp刚才:)希望这对PushSharp用户有帮助。