gpt4 book ai didi

c# - 在 Xamarin.iOS 中阅读 Parse.com 推送负载

转载 作者:行者123 更新时间:2023-11-29 01:23:09 24 4
gpt4 key购买 nike

我想阅读 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,它应该提供一些关于有效负载结构的线索。

关于c# - 在 Xamarin.iOS 中阅读 Parse.com 推送负载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34357823/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com