现在,我能够从解析服务接收有效载荷,如下所示:
{
"where": {
"objectId": "00000011",
"deviceType": "ios"
},
"data": {
"alert": "You have a new Message",
"sound": "alert_chat.mp3",
"viewController": "chat_controller",
"nick_from": "username1",
"nick_to": "username2"
}
}
使用以下代码行,我可以知道我想在didReceiveRemoteNotification的Appdelegate上进行筛选的viewController:
if([[userInfo objectForKey:@"viewController"] isEqual: @"chat_controller"]){
NSLog(@"ViewController:%@", [userInfo objectForKey:@"viewController"]);
}
现在,我想选择聊天控制器,还要将值(nick_from,nick_to)传递给该特定的viewController,因为此ViewController期望使用这2个值来调用这2个用户之间的对话。
编辑
我为这个问题找到的解决方案如下。
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
[(UITabBarController *)self.window.rootViewController setSelectedIndex:2];
UINavigationController *nav = [[(UITabBarController *)self.window.rootViewController viewControllers]objectAtIndex:2];
UIViewController *detail = [mainStoryboard instantiateViewControllerWithIdentifier:@"conversation_detail"];
nav.navigationBar.barTintColor = [UIColor colorWithRed:0.098 green:0.737 blue:0.611 alpha:1];
nav.navigationBar.tintColor = [UIColor whiteColor];
[nav.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];
nav.navigationBar.translucent = YES;
[nav pushViewController:detail animated:NO];
最佳答案
通过AppDelegate中的[NSNotificationCenter defaultCenter]
广播NSNotification,让第一个视图控制器侦听该通知,如果是时候查询详细信息控制器,则在prepareForSegue:
中设置对象
关于ios - 当推送通知到达设备并将有效载荷值传递给目标ViewController时,如何在Appdelegate上执行Segue?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24231395/