单击远程通知后启动视图控制器?

时间:2014-08-25 07:02:14

标签: ios notifications

我希望在点击远程通知后打开一个以tabbarviewcontroller为根的viewcontroller。这可能吗?

我正在打电话,所以我不能单独突出显示代码,但这里是

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{


If(launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey]){
//what do I put here?

}

1 个答案:

答案 0 :(得分:0)

试试这个(我假设你的方法在你的AppDelegate类中)

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{


      If(launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey])
      {

        UITabBarController * tabController  = (UITabBarController*)_window.rootViewController;
        YourViewController * yvc = (YourViewController*)[tabController.viewControllers objectAtIndex:index];
        [self.window.rootViewController presentViewController:yvc animated:YES completion:nil];
      }
}

(或) 编辑:这可能有用

AppDelegate* appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
MainViewController *mvc = (MainViewController *)appDelegate.window.rootViewController;    
YourViewController *yvc = (YourViewController*)[mvc.storyboard instantiateViewControllerWithIdentifier:@"ViewStoryBoardID"];
[self.window.rootViewController presentModalViewController:yvc animated:YES];