提取“警报"来自推送通知的文本 [英] Extract "alert" text from push notification
本文介绍了提取“警报"来自推送通知的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在我的应用程序委托文件中放置了以下代码.从理论上讲,它应该从推送通知中提取消息并将其显示在 UIAlertview
中 - 但它只显示标题和蜡烛按钮,仅此而已.有人能看出我哪里出错了吗?
I have the following code placed in my app delegate file. In theory, it should be extracting the message from the push notification and displaying it in a UIAlertview
- yet it displays the title and the candle button, and nothing else. Can anybody see where I am going wrong?
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
[PFPush handlePush:userInfo];
pushText = [userInfo objectForKey:@"alert"];
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:NSLocalizedString(@"News", "")
message:pushText
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles: nil];
[alert show];
}
推荐答案
push payload 的结构如下:
The push payload has the following structure:
{
"aps" : {
"alert" : "Push notification text"
}
}
所以你需要先拉出aps"字典,然后你才能检索到alert"键的值:
So you need to pull out the "aps" dictionary first and then you can retrieve the value for the "alert" key:
pushText = [[userInfo objectForKey:@"aps"] objectForKey:@"alert"];
这篇关于提取“警报"来自推送通知的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文