在调用application:didBecomeActive(iOS)时,rootViewController是否总是准备好提出提示? [英] Is rootViewController always ready to present a segue by the time application:didBecomeActive is called (iOS)?

查看:364
本文介绍了在调用application:didBecomeActive(iOS)时,rootViewController是否总是准备好提出提示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序在情节提要中有一个rootViewController设置.我最初问的是这个问题,但我可以看到现在要问的是一个错误的问题:

My app has a rootViewController setup in a storyboard. I originally asked this question, but I can see that it is the wrong question to ask now:

是否总是调用rootViewController的viewDidLoad方法 在应用程序委托中的application:didBecomeActive之前?那会吗 viewDidLoad方法总是在之前完成 application:didBecomeActive被调用,或者两个都可以运行 并发?

Is the viewDidLoad method of the rootViewController always called before application:didBecomeActive in the app delegate? Does that viewDidLoad method always finish before application:didBecomeActive is called, or can the two run concurrently?

我可以运行测试,但是我知道这些测试没有考虑到 每种情况.我想了解是否有硬性规定 适用于这里,或者如果我可能正在处理种族 在某个时候的条件.据我所知, rootViewController似乎在被调用并完成之前 application:didbecomeActive被调用,但是我不知道是否 这是我可以依靠的东西.

I can run tests, but I know that these tests don't take into account every situation. I want to understand if there are hard and fast rules that apply here, or if I might possibly be dealing with race conditions at some point. From what I can tell, viewDidLoad of the rootViewController seems to be called and finished before application:didbecomeActive is called, but I can't figure out if this is something I can rely on.

我正在使用iOS 11和Xcode 9.

I am using iOS 11 and Xcode 9.

我的rootViewController用于显示我的appUpdating视图,密码视图,法律条款视图,handleImportedFile视图和tabbarcontroller.这就像各种启动协调器一样,因为我的加载过程非常复杂.现在,我正在移动用户的sqlite数据库的位置,而我的某些用户数据库非常庞大.它必须在后台完成,但是在主队列上运行hud时,因为在完成此操作之前应用程序无法显示数据.如果我在application:didFinishLaunchingWithOptions期间执行此操作,则某些用户正在使用看门狗计时器.所以我想将加载过程移到application:didBecomeActive(我有一个标志告诉我应用程序是否从终止启动).完成运行后,rootViewController将对相关视图执行segue.但是我认为rootViewController需要在那时加载,并且我不确定情况是否总是如此.

My rootViewController serves to show my appUpdating view, passcode view, my legal terms view, my handleImportedFile view, and my tabbarcontroller. It is like a launch coordinator of sorts, because my loading process is extremely complicated. Now I am moving the location of the user's sqlite database, and some of my user's databases are huge. It has to be done in the background, but while a hud is running on the main queue, because the app cannot show data until this is done. If I do this during application:didFinishLaunchingWithOptions, some users are getting the watchdog timer. So I want to move the loading process to application:didBecomeActive (I have a flag to tell me if app is launching from terminated). When it is done running, the rootViewController performs a segue to the pertinent view. But I think rootViewController needs to have loaded by that time, and I am not sure that that is always the case.

基本上,在下面的代码中,我试图弄清楚是否导致"c8>"在安全的地方"被调用,而这会导致rootViewController(我称为masterController)执行segue,还是在任何情况,此时让rootViewController执行segue可能为时过早.

Basically, in the code below, I am trying to figure out if [self.masterController showApplicableView], which causes the rootViewController (which I call masterController) to perform a segue, is called in a 'safe place', or if, in any case, it could possibly be too early to have the rootViewController perform a segue at this point.

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

    self.masterController = (MasterViewController*)self.window.rootViewController;
    self.activatingFromTerminated = YES;

    return YES;
}

- (void)applicationWillEnterForeground:(UIApplication *)application {

    self.activatingFromTerminated = NO;
}

- (void)applicationDidBecomeActive:(UIApplication *)application {

    if (_activatingFromTerminated) {

        self.activatingFromTerminated = NO;

        [[CoreDataController sharedManager] loadStoreWithCompletionHandler:^(NSError * _Nullable error) {

            if ([CoreDataController sharedManager].storeLoaded) {

                [self.masterController showApplicableView];//performs applicable segue
            }
        }];
    }
}

推荐答案

据我所知,rootViewController的viewDidLoad似乎是在调用application:didbecomeActive之前被调用并完成的,但是我不知道这是否值得依靠.

From what I can tell, viewDidLoad of the rootViewController seems to be called and finished before application:didbecomeActive is called, but I can't figure out if this is something I can rely on.

不是,您不应该.您完全不需要担心这一点.您认为自己需要知道的事实是代码中的不良气味.这些是来自两个完全不同区域(应用程序和视图控制器)的生命周期事件,它们的相对时间不应该引起您的关注.尽一切适合该事件的含义.

It isn’t and you shouldn’t. You shouldn’t be concerned about this at all. The fact that you think you need to know this is a Bad Smell in your code. These are lifetime events from two completely different areas (the app and a view controller) and their relative timing should be no concern of yours. Do in each what is appropriate to the meaning of that event.

这篇关于在调用application:didBecomeActive(iOS)时,rootViewController是否总是准备好提出提示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆