gpt4 book ai didi

ios - 从推送通知中将 JSON 有效负载数据转换为字符串

转载 作者:行者123 更新时间:2023-12-01 18:15:15 25 4
gpt4 key购买 nike

我试图将我的 JSON 有效负载数据从推送通知中获取到字符串中。

{
aps = {
alert = "BG push";

sound = ,
};
}

我研究了 SO 和 Parse 并尝试了各种方法,包括 Apple Push Notification with Sending Custom Data但是我的字符串重新运行 (null) 或如本示例中的 JSON 格式

我想要 alert数据 "BG Push"在一个字符串中,所以我可以把它放在一个警报 View 中
 - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {

if ( application.applicationState == UIApplicationStateActive ){

// app was already in the foreground
[PFPush handlePush:userInfo]; //<-----userInfo returns payload data in JSON format

}

else {
// app was just brought from background to foreground
NSLog(@"App was in background and opened from Push message");

UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Megger"
message: [NSString stringWithFormat:@"%@", userInfo]
delegate:self
cancelButtonTitle: @"Ok"
otherButtonTitles: nil];

[alert show];

}
}

最佳答案

NSString *alert = userInfo[@"aps"][@"alert"];

UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:@"Megger"
message: [NSString stringWithFormat:@"%@", alert]
delegate:self
cancelButtonTitle: @"Ok"
otherButtonTitles: nil];

[alertView show];

关于ios - 从推送通知中将 JSON 有效负载数据转换为字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22582041/

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