我对所有iOS推送通知域都不熟悉。我已经使用下面的代码尝试了一个基本的推送通知,它工作得很好。我使用"using JdSoft.Apple.Apns.Notifications;“来完成这个任务。代码如下:
Notification alertNotification = new Notification(testDeviceToken);
alertNotification.Payload.Alert.Body = "Hello World";
alertNotification.Payload.Sound = "default";
alertNotification.Payload.Badge = 1;
这为iPhone提供了以下结构的输出:
{
aps = {
alert = "Hello World";
badge = 1;
sound = default;
};
}
我现在需要添加一个自定义标记,如下所示:
{
"aps": {
"alert": "Hello World",
"sound": "default",
"Person": {
"Address": "this is a test address",
"Name": "First Name",
"Number": "023232323233"
}
}
}
我发现很难在"aps“中找到"Person”。我还知道您可以使用以下代码添加自定义属性:
Newtonsoft.Json.JsonConvert.SerializeObject(stat));(“个人”,alertNotification.Payload.AddCustom
但是上面的代码没有添加"aps“标签。请告诉我如何实现这一目标?
发布于 2019-07-10 19:40:58
我使用的是push sharp库。
public static JObject CreatePayload(APNSNotification apnsNotification, object content, int Ntype)
{
var payload = new Dictionary<string, object>();
var aps = new Dictionary<string, object>();
if ((int)NotificationType.CONFERENCE == Ntype)
{
var confNotification = new ConferenceNotification();
confNotification = (ConferenceNotification)content;
aps.Add("alert", confNotification.title);
aps.Add("subtitle", confNotification.body);
aps.Add("badge", confNotification.badgeCount);
payload.Add("aps", aps);
payload.Add("confId", confNotification.confId);
payload.Add("pageFormat", confNotification.pageFormat);
payload.Add("pageTitle", confNotification.pageTitle);
payload.Add("webviewURL", confNotification.webview_URL);
payload.Add("notificationBlastID", confNotification.notificationBlastID);
payload.Add("dataValue", confNotification.dataValue);
payload.Add("pushtype", "Events");
}
else if ((int)NotificationType.NEWS == Ntype)
{
var newsNotification = new NewsNotification();
newsNotification = (NewsNotification)content;
aps.Add("alert", newsNotification.title);
aps.Add("subtitle", newsNotification.subtitle);
aps.Add("badge", newsNotification.badgeCount);
payload.Add("aps", aps);
payload.Add("articleId", newsNotification.articleId);
payload.Add("msgcnt", newsNotification.msgcnt);
payload.Add("type", newsNotification.type);
payload.Add("pushtype", "News");
}
return JObject.Parse(Newtonsoft.Json.JsonConvert.SerializeObject(payload));
}
https://stackoverflow.com/questions/15834581
复制相似问题