美文网首页
关于APP启动的时候,就弹出登录,或者订阅,遇到的问题

关于APP启动的时候,就弹出登录,或者订阅,遇到的问题

作者: 不会武功的陈真 | 来源:发表于2023-05-24 16:43 被阅读0次
    1. 在APP打开的时候就调用这个方法,有时候会失效
        LoginVC *vc = [LoginVC new];
        vc.modalPresentationStyle = UIModalPresentationFullScreen;
        [self presentViewController:vc animated:NO completion:nil];
    

    a)、我们说说失效情况, 如果我们的跟视图是self.window.rootViewController = rootVc
    那么我们在rootVc的viewDidLoad 中调用 [self presentViewController:vc animated:NO completion:nil]; 肯定是不成功的。
    会报一个错误(null)) whose view is not in the window hierarchy.

    例如我们rootVC 是 UINavigationController或者是 UITabBarControllerUIViewController,那么我们在他们的viewDidLoad方法中调用[self presentViewController:vc animated:NO completion:nil];就会失效

    b)、正确的使用情况, 如果我们的跟视图是self.window.rootViewController = rootVc

    rootVc 是UINavigationController,那我们在UINavigationControllerrootViewControllerviewDidLoad 方法中调用 [self presentViewController:vc animated:NO completion:nil]; ,就能够present 成功

    同理 rootVc 是UITabBarController,那我们在UITabBarControllerfirst ChildViewControllerviewDidLoad 方法中调用 [self presentViewController:vc animated:NO completion:nil]; ,就能够present 成功

    2.在APP打开的时候找不到UIWindow

        NSLog(@" ---- %@",[UIApplication sharedApplication].keyWindow);
    

    还是用上面的问题,替换[self presentViewController:vc animated:NO completion:nil];代入就好

    相关文章

      网友评论

          本文标题:关于APP启动的时候,就弹出登录,或者订阅,遇到的问题

          本文链接:https://www.haomeiwen.com/subject/mcxqedtx.html