我想阅读iOS推送“提醒”消息
parse.com在他们的网站上有这个例子
ParsePush.ParsePushNotificationReceived += (sender, args) => {
var payload = args.Payload;
object objectId;
if (payload.TryGetValue("objectId", out objectId)) {
DisplayRichMessageWithObjectId(objectId as string);
}
};
但是如何从有效负载中读取警报消息?
解决方案
string message = "";
try
{
var payload = args.Payload;
object aps;
if (payload.TryGetValue("aps", out aps))
{
string payloadStr = "";
try
{
payloadStr = aps.ToString();
}
catch (Exception e)
{
}
try
{
var match = Regex.Match(payloadStr, @"alert = (.*);\n");
if (match.Success)
{
string alertText = match.Groups[1].Value;
message = alertText;
}
}
catch (Exception)
{
}
}
}
答案 0 :(得分:1)
试试这个:
ParsePush.ParsePushNotificationReceived += (sender, args) => {
var payload = args.Payload;
object aps;
if (payload.TryGetValue("aps", out aps)) {
string payloadStr = aps as string;
}
};
此外,应该有一个args.PayloadString
,它应该提供有关有效载荷结构的一些线索。