【发布时间】:2018-03-18 19:26:15
【问题描述】:
我一直试图弄清楚如何在我的 asp.net web api 中发送推送通知。我看到有多种方法可以通过设备本身和后端在集线器中注册设备。我想使用第一种方法,并找到了一些教程,但我不知道如何从后端发送请求。我尝试了以下代码,但它给了我 401 Unauthorized 错误:
[HttpGet]
public async Task<HttpResponseMessage> NotTry()
{
NotificationOutcome outcome;
HttpStatusCode ret = HttpStatusCode.InternalServerError;
string notif = "{ \"data\" : {\"message\":\"hello\"}}";
outcome = await Notifications.Instance.Hub.SendGcmNativeNotificationAsync(notif);
if (outcome != null)
{
if (!((outcome.State == NotificationOutcomeState.Abandoned) ||
(outcome.State == NotificationOutcomeState.Unknown)))
{
ret = HttpStatusCode.OK;
}
}
return Request.CreateResponse(ret);
}
如果有人能给我一个方向,我将不胜感激。我正在失去理智寻找解决方案......
【问题讨论】:
标签: azure asp.net-web-api push-notification azure-notificationhub