0
我正在使用google的GCM API開發wcf推送通知服務。我創建了一項服務,發送到使用我的應用程序的所有設備,但是,我想要針對某個設備。我想我必須使用我註冊GCM服務時獲得的令牌。但我不知道在哪裏以及如何暗示它。大多數在線帖子都是在PHP中,當我看到代碼時,我有點困惑。任何一個使用C#implmentation建議或一般可能是? 這裏是我的代碼爲所有設備:提前使用gcm的android推送通知
public bool notify(string sender, string message)
{
var jGcmData = new JObject();
var jData = new JObject();
bool Value;
jData.Add("message", message);
jData.Add("name", sender);
jGcmData.Add("to", "/topics/global");
jGcmData.Add("data", jData);
var url = new Uri("https://gcm-http.googleapis.com/gcm/send");
try
{
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.TryAddWithoutValidation(
"Authorization", "key=" + API_KEY);
Task.WaitAll(client.PostAsync(url,
new StringContent(jGcmData.ToString(), Encoding.Default, "application/json"))
.ContinueWith(response =>
{
Console.WriteLine(response);
Console.WriteLine("Message sent: check the client device notification tray.");
}));
}
Value = true;
}
catch (Exception e)
{
Console.WriteLine("Unable to send GCM message:");
Console.Error.WriteLine(e.StackTrace);
Value = false;
}
return Value;
}
的感謝!
我看到很多帖子使用pushSharp,我會看看它。謝謝! – user3406302