阅读Xamarin.iOS中的Parse.com推送负载
本文关键字:负载 com Parse Xamarin iOS 中的 阅读 | 更新日期: 2023-09-27 18:27:16
我想阅读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)
{
}
}
}
试试这个:
ParsePush.ParsePushNotificationReceived += (sender, args) => {
var payload = args.Payload;
object aps;
if (payload.TryGetValue("aps", out aps)) {
string payloadStr = aps as string;
}
};
此外,应该有一个args.PayloadString
,它应该提供一些关于有效载荷结构的线索。