【问题标题】:load storyboard viewcontroller from didReceiveRemoteNotification从 didReceiveRemoteNotification 加载故事板视图控制器
【发布时间】:2014-12-03 09:17:43
【问题描述】:

我使用了故事板。该应用是基于标签栏控制器的。

点击推送通知时,我想从情节提要中打开特定的“通知事件”视图控制器。” 我不知道didReceiveRemoteNotification 中的代码是什么。

我的代码是:

NSString *notification = [[userInfo valueForKey:@"aps"] valueForKey:@"alert"];

Dashboard *ds = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"Dashboard"] ;
NotificationTable *nt = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"NotificationBoard"] ;

UIStoryboardSegue *segue = [UIStoryboardSegue segueWithIdentifier:@"NotificationBoardTable"
                                                           source:ds
                                                      destination:nt
                                                   performHandler:^{
                                                   }];

[ds performSegueWithIdentifier:@"NotificationBoardTable" sender:ds];

【问题讨论】:

  • 朋友们,有谁能帮帮我吗?
  • 你的意思是在收到远程通知后要更改 ViewController 吗?
  • 你完全是老兄。 @horst

标签: ios objective-c iphone xcode ios7


【解决方案1】:

让我们看看这是不是你想要的:

[[NSNotificationCenter defaultCenter] postNotificationName:kReceiveNotification object:nil userInfo:YOUR_DATA_PASSING];

然后在您的自定义选项卡视图控制器中接收它:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(YOUR_HANDLE_METHOD:) name:kReceiveNotification object:nil];

释放时不要忘记移除观察者:

[[NSNotificationCenter defaultCenter] removeObserver:self];

终于在那个方法中:

[self setSelectedIndex:xxx];//If you want to switch tab

【讨论】:

  • 好吧,我也试过了。但是应用程序没有在后台运行。如何在远程通知到来时发布和处理通知。因为当通知到来时“didReceiveRemoteNotification”不再被调用。
  • 如果您通过点击通知启动应用程序,您需要在 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { NSDictionary *userInfo = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]; if (userInfo == NULL) { NSLog(@"didFinishLaunchingWithOptions 用户启动 userinfo: %@", userInfo); } else { NSLog(@"didFinishLaunchingWithOptions 通知启动 userinfo: %@", userInfo); } }
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-01
  • 2021-08-05
  • 2016-11-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多