首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >识别推送通知消息

问识别推送通知消息
EN

Stack Overflow用户
提问于 2012-09-06 14:33:14
回答 1查看 5.9K关注 0票数 1

在我的项目中,我想通过推送通知显示事件和优惠,但问题是,我能够显示事件或优惠,而不是两者。有没有办法识别推送通知的消息?代码如下:

代码语言:javascript
复制
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
    NSString *message = nil;
    id alert = [userInfo objectForKey:@"alert"];

    if ([alert isKindOfClass:[NSString class]]) {
        message = alert;
    } else if ([alert isKindOfClass:[NSDictionary class]]) {
        message = [alert objectForKey:@"body"];
    }
    if (alert) {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Title"
                                                            message:@"AThe message." delegate:self
                                                  cancelButtonTitle:@"button 1"
                                                  otherButtonTitles:@"button", nil];
        [alertView show];
    }

    NSString *contentsInfo = [userInfo objectForKey:@"contTag"];
    NSLog(@"Received contents info : %@", contentsInfo);

    NSString *nibName = [AppDelegate fetchNibWithViewControllerName:@"EventsViewController"];

    EventsViewController *evc = [[EventsViewController alloc] initWithNibName:nibName bundle:nil];

    evc.newEvent = YES;

    [self.navigationController pushViewController:evc animated:YES];

    [UIApplication sharedApplication].applicationIconBadgeNumber = [[[userInfo objectForKey:@"aps"] objectForKey: @"badgecount"] intValue];
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-09-06 14:53:01

alert始终是一个有两个键的NSDictionary:body和show-view。前者的值是警报消息,后者是Boolean (false或true)。如果为false,则不显示警报的视图按钮。默认情况下,显示View按钮,如果用户点击该按钮,将启动应用程序。

检查docs

要识别消息的类型,可以提供额外的字段,如here所述

示例:

代码语言:javascript
复制
{
   "aps":{
      "badge":1,
      "alert":"This is my special message!",
      "mycustomvar1":"123456",
      "mycustomvar2":"some text",
      "myspecialtext":"This is the best!",
      "url":"http://www.mywebsite.com"
   }
}
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12294214

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档