ios - 与推送交互后导航到特定 ViewController

标签 ios objective-c swift uinavigationcontroller apple-push-notifications

当用户通过与推送通知交互进入 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/

相关文章:

swift - 整数相乘

ios - 在 iOS 11 中切换任务时出现虚假旋转事件

ios - 如何在 swift 3 的 UITableView 中创建和使用变量

objective-c - 查找可用的 USB 设备 Mac OS X

iphone - 图像的圆角

ios - 使用 setViewControllers 时,viewWillAppear、viewDidAppear 和 viewWillDisappear 不会在 iOS 5 上被调用

swift - 在一个字符串中多次使用 NSAttributedString

ios - UIDatePicker 设计中的错误

iphone - iOS如何停止 View 旋转

ios - 创建一个组合的解析查询?