无法从webapi向IOS发送推送通知?

时间:2017-10-13 06:15:19

标签: c# .net asp.net-web-api

您好我正在开发webapi中的Web应用程序并创建推送通知。我正面临着以下问题。每当我写下面的代码,我都能发送消息。

      String payload;
                string strmsgbody = "";
                int totunreadmsg = 20;
                strmsgbody = "Hey Ashish";
 Request.SaveAs(System.Web.HttpContext.Current.Server.MapPath("APNSduringdevice.txt"), true);
                payload = "{\"aps\":{\"alert\":\"" + strmsgbody + "\",\"badge\":" + totunreadmsg.ToString() + ",\"sound\":\"mailsent.wav\"},\"acme1\":\"bar\",\"acme2\":42}";

每当我用下面的代码替换strmsgbody时

string IOSmessage = "XYZ Financing" + RequestType;
            string IOScontentTitle = RequestType + " status updated.";
            string IOSpostData =
          "{\"data\": {\"contentTitle\":\"" + IOScontentTitle + "\", " +
                       "\"message\": \"" + status + "\"}}";

在调试器中,我可以看到下面为上面生成的代码。

"{\"aps\":{\"alert\":\"{\"data\": {\"contentTitle\":\"Lease status updated.\", \"message\": \"CompletedStatusmessage\"}}\",\"badge\":20,\"sound\":\"mailsent.wav\"},\"acme1\":\"bar\",\"acme2\":42}"

我无法发送消息。我可以知道我在上面的代码中遗漏了什么吗?任何帮助,将不胜感激。谢谢。

1 个答案:

答案 0 :(得分:2)

用于在iOS设备上获取推送通知的有效负载应为

{
    "aps" : {
        "alert" : {
            "title" : "Lease status updated.",
            "body" : "CompletedStatusmessage"
        },
        "badge" : 20,
        "sound" : "mailsent.wav "
    },
    "acme1" : "bar",
    "acme2" : 42
}

以及您要发送的内容

    "{
    "aps ":{
      " alert ":" {
        "data": {
            "contentTitle": "Lease status updated.",
            "message": "CompletedStatusmessage"
        }
    }

",
" badge ":20,
" sound ":"mailsent.wav "},
" acme1 ":" bar ",
  " acme2 ":42
}"