当用户通过与推送通知交互进入 iOS 应用程序时,我很难找到有关管理导航流的最佳方法的任何好信息。
就我而言,我有一个 UITabController,其中每个选项卡都有一个根 UINavigationController。例如,假设插入应该引导我到第二个选项卡。让事情变得有点复杂,根据推送的 json,我可能想从根开始,或者我可能想填充一堆 viewController,最后一个由于 json 中的变量而以特定方式初始化。
这个问题可以在概念上重新构建:当用户通过 PushNotification(从终止状态和后台状态)激活应用程序时,填充 NavigationController 堆栈并显示 n-1 ViewController 的正确方法是什么。使用哪些委托(delegate)方法,以及如何避免竞争条件,因为 ViewController 的可能未初始化。
谢谢
最佳答案
AppDelegate.h
在AppDelegate.h文件中创建一个UITabBarController对象
@property (nonatomic, strong) UITabBarController *tabBarController;
AppDelegate.m
定义处理远程推送通知的方法
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
CustomViewController1 *view1 = [[CustomViewController1 alloc] initWithNibName:@"CustomViewController1" bundle:nil];
UINavigationController *view1 = [[UINavigationController alloc] initWithRootViewController:view1];
CustomViewController2 *view2 = [[CustomViewController2 alloc] initWithNibName:@"CustomViewController2" bundle:nil];
UINavigationController *view2 = [[UINavigationController alloc] initWithRootViewController:view2];
CustomViewController3 *view3 = [[CustomViewController3 alloc]initWithNibName:@"CustomViewController3" bundle:nil];
UINavigationController *view3 = [[UINavigationController alloc] initWithRootViewController:view3];
NSArray *arrNavControllers = [NSArray arrayWithObjects:view2, view2, view2, nil];
// Set here CustomViewController On Which you want to Naviagte
[self.tabBarController setSelectedIndex:0];
[self.window setRootViewController:self.tabBarController];
}
关于ios - 与推送交互后导航到特定 ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32109090/