[英]How to send a push notification on app (andorid/ios) that uses webview and on the back-end is .NET WebAPI
[英]Unable to send push notification to IOS from webapi?
嗨,我正在用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}"
我無法發送消息。 我可以知道上面的代碼中缺少什么嗎? 任何幫助,將不勝感激。 謝謝。
在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
}"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.