为什么我的presentModalViewController无法在AppDelegate中运行?

Pie*_*ter 3 xcode storyboard ios

为什么我要在AppDelegate中使用presentModalViewController? - 处理didReceiveLocalNotification,所以我可以在我的应用程序顶部启动一个单独的modalView来处理通知

我的视图架构是什么样的? - 使用故事板 - MainStoryBoard: - > TabBarController-> NavigationController

发生了什么? - 没什么,这就是问题:-D - 当我从UILocalNotification按下操作按钮时,应用程序会打开,但只显示tabbarcontroller中的最后一个打开视图.

正如您在下面看到的,我最后的努力是在当前视图的顶部呈现modalViewController,如下所示: [self.window.rootViewController.tabBarController.selectedViewController.navigationController presentModalViewController:navigationController animated:YES];

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

UIApplicationState state = [application applicationState];
if (state == UIApplicationStateInactive) {
    // Application was in the background when notification was delivered.
    NSLog(@"Received notification while in the background");
}
else {
    NSLog(@"Received notification while running.");
}

MedicationReminderViewController *controller = [[UIStoryboard storyboardWithName:@"ModalStoryBoard" bundle:nil] instantiateViewControllerWithIdentifier:@"MedicationReminderVC"];

UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:controller];
[self.window.rootViewController.tabBarController.selectedViewController.navigationController presentModalViewController:navigationController animated:YES];
Run Code Online (Sandbox Code Playgroud)

}

self.window.rootViewController.tabBarController.selectedViewController.navigationController

[self.window.rootViewController.tabBarController.selectedViewController.navigationController presentModalViewController:navigationController animated:YES];

更新

似乎这是零: - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {

UIApplicationState state = [application applicationState];
if (state == UIApplicationStateInactive) {
    // Application was in the background when notification was delivered.
    NSLog(@"Received notification while in the background");
}
else {
    NSLog(@"Received notification while running.");
}

MedicationReminderViewController *controller = [[UIStoryboard storyboardWithName:@"ModalStoryBoard" bundle:nil] instantiateViewControllerWithIdentifier:@"MedicationReminderVC"];

UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:controller];
[self.window.rootViewController.tabBarController.selectedViewController.navigationController presentModalViewController:navigationController animated:YES];
Run Code Online (Sandbox Code Playgroud)

}

[self.window.rootViewController presentModalViewController:navigationController animated:YES];

Nev*_*rBe 6

试试这个 :

[self.window.rootViewController presentModalViewController:controller
                                                  animated:YES];
Run Code Online (Sandbox Code Playgroud)