识别推送通知消息(Identifying the Push Notification Message

2019-09-22 04:23发布

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

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

Answer 1:

alert始终是一个NSDictionary有两个关键:身体和显示视图。 前者的值是警告消息,而后者是一个Booleanfalsetrue )。 如果false ,警报的视图按钮不会显示。 默认是显示视图按钮,如果用户点击它,启动应用程序。

检查文档

要确定您可以提供附加字段消息的类型,描述在这里

例:

{
   "aps":{
      "badge":1,
      "alert":"This is my special message!",
      "mycustomvar1":"123456",
      "mycustomvar2":"some text",
      "myspecialtext":"This is the best!",
      "url":"http://www.mywebsite.com"
   }
}


Answer 2:

审查这个环节,可以帮助你..

http://mobiforge.com/developing/story/programming-apple-push-notification-services



文章来源: Identifying the Push Notification Message