如果应用程序位于前台,则单击本地通知打开特定视图控制器?

时间:2016-04-08 11:09:59

标签: ios objective-c uiviewcontroller notifications uilocalnotification

我尝试在点击本地通知时打开特定的视图控制器,如果应用在后台,我无法执行此操作,因为我在[launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];方法中没有applicationDidBecomeActive 。如果可以,请提供帮助,提前致谢。

1 个答案:

答案 0 :(得分:1)

喜欢

 UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        yourViewController *obj=[storyboard instantiateViewControllerWithIdentifier:@"yourViewControllerStoryboardID"];
       // [self.window.rootViewController.navigationController pushViewController:obj animated:YES];
          self.window.rootViewController = obj;

<强>更新

  - (void)applicationDidBecomeActive:(UIApplication *)application {

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
MapViewController *obj=[storyboard instantiateViewControllerWithIdentifier:@"Map"];
// [self.window.rootViewController.navigationController pushViewController:obj animated:YES];
self.window.rootViewController = obj;



}

<强> UPDATE1

您可以在此处获取本地通知操作

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification

有关完整教程,请参阅this