Ios 获取本地通知时重定向到特定视图控制器

Ios 获取本地通知时重定向到特定视图控制器,ios,objective-c,uilocalnotification,Ios,Objective C,Uilocalnotification,我正在尝试实现本地通知,其工作正常,但我的问题是,当我的应用程序位于前台,并且我从服务器获得推送时,它将向我发出警报,但当我点击该警报并尝试在我的主视图控制器上使用此简单的应用程序代理文件中的代码重定向时 - (void)didTapOnNotificationView:(CMNavBarNotificationView *)notificationView { UIStoryboard *storyboard = [[self.window rootViewController] st

我正在尝试实现本地通知,其工作正常,但我的问题是,当我的应用程序位于前台,并且我从服务器获得推送时,它将向我发出警报,但当我点击该警报并尝试在我的主视图控制器上使用此简单的应用程序代理文件中的代码重定向时

- (void)didTapOnNotificationView:(CMNavBarNotificationView *)notificationView
{
    UIStoryboard *storyboard = [[self.window rootViewController] storyboard];
    HomeViewController *obj_home=[storyboard instantiateViewControllerWithIdentifier:@"Home"];
    UINavigationController* navigationViewController_test=[[UINavigationController alloc]initWithRootViewController:[storyboard instantiateViewControllerWithIdentifier:@"Home"]];

    [navigationViewController_test pushViewController:obj_home animated:YES];
}

这个代码只会显示黑屏,有人能告诉我哪里出错了吗?是的,对于本地通知警报,我正在使用第三方工具(
CMNavBarNotificationView
)并使用其委托方法(
didTapOnNotificationView

,您需要将导航控制器与导航堆栈中当前的viewcontroller链接起来。在下面的代码中,我使用rootviewcontroller呈现/推送HomeviewController,您可以用您想要的任何控制器替换它

 - (void)didTapOnNotificationView:(CMNavBarNotificationView *)notificationView
    {
        UIStoryboard *storyboard = [[self.window rootViewController] storyboard];
        HomeViewController *obj_home=[storyboard instantiateViewControllerWithIdentifier:@"Home"];



      // either present the navigation controller as a modal 


        UINavigationController* navigationViewController_test=[[UINavigationController alloc]initWithRootViewController:obj_home];

        [self.window.rootViewController presentViewController:navigationViewController_test animated:YES completion:^{}];

     // OR push the home view. Here my rootViewController is a navigation controller, so I am pushing the home view directly from it. You can push it from any of the controller that is in the current navigation controller stack.

        [(UINavigationController *)self.window.rootViewController pushViewController:obj_home animated:YES];

    }

希望这有帮助。

您是在谈论本地通知还是推送通知?谈论本地通知,但当我收到消息时,我只想在homeview/firstview控制器上重定向。好的,我已经编辑了您的问题,以删除推送通知的所有引用。好的。我解决了它。您能帮助我在应用程序处于后台以及在通知区域点击通知时调用哪个方法吗?当您在应用程序处于后台状态时点击通知时,以下方法将被称为-(void)application:(UIApplication*)应用程序didReceiveLocalNotification:(UILocalNotification*)通知{}