提取"警报"从推送通知文本 [英] Extract "alert" text from push notification

查看:145
本文介绍了提取"警报"从推送通知文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的code放置在我的应用程序委托文件。从理论上讲,它应该提取的推送通知的消息,并在 UIAlertView中显示它 - 但它显示的标题和蜡烛按钮,而不是其他。任何人都可以看到我错了?

   - (无效)应用:(*的UIApplication)的应用didReceiveRemoteNotification:(NSDictionary的*){用户信息
    [PFPush handlePush:用户信息];
    pushText = [USERINFO objectForKey:@警报];
    UIAlertView中*警报= [[UIAlertView中页头]
                          initWithTitle:NSLocalizedString(@新闻,)
                          消息:pushText
                          代表:无
                          cancelButtonTitle:@确定
                          otherButtonTitles:无];
    [警报显示]
}


解决方案

推载荷的结构如下:

  {
    APS:{
             警告:推送通知文本
             }
}

所以,你需要拉出APS字典冷杉,然后你可以检索警戒键的值:

  pushText = [[USERINFO objectForKey:@APS] objectForKey:@警报];

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];
}

解决方案

The push payload has the following structure:

{
    "aps" : {
             "alert" : "Push notification text"
             }
}

So you need to pull out the "aps" dictionary firs and then you can retrieve the value for the "alert" key:

 pushText = [[userInfo objectForKey:@"aps"] objectForKey:@"alert"];

这篇关于提取"警报"从推送通知文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆