如何判断控制器何时从后台恢复? [英] How to tell when controller has resumed from background?

查看:95
本文介绍了如何判断控制器何时从后台恢复?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我想在我即将推出的iPhone应用程序中支持应用程序切换,并且我已经在我的应用程序委托中实现了所有正确的委托方法。因此,当用户恢复应用程序时,我可以在NSLog中看到他们的活动。但是,我怎么能告诉我的应用程序已恢复控制器?有没有一种方法可以放在我的控制器中告诉我应用程序已在所述控制器中恢复?我问的原因是因为我的应用程序处理自己的URL架构,我想根据启动的URL更新视图。任何帮助将不胜感激。

So I want to support app switching in my upcoming iPhone app and I've implemented all the proper delegate methods in my application delegate. So when the user resumes the application, I can see their activity in the NSLog and all. However, how can I tell my app has resumed a controller? Is there a method I can put in my controller to tell me the app has resumed in said controller? Reason I ask is because my application handles its own URL schema, and I want to update the view depending on the URL launched. Any help will be greatly appreciated.

提前致谢

推荐答案

您可以让控制器观察 UIApplicationWillEnterForeground 通知。它可能看起来像这样:

You can have you your controller observe the UIApplicationWillEnterForeground notification. It probably would look something like this:

- (void) viewDidLoad
{
    [super viewDidLoad];
    //do stuff here
    if(&UIApplicationWillEnterForegroundNotification) { //needed to run on older devices, otherwise you'll get EXC_BAD_ACCESS
        NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
        [notificationCenter addObserver:self selector:@selector(enteredForeground:) name:UIApplicationWillEnterForegroundNotification object:nil];
    }


}
- (void)enteredForeground:(NSNotification*) not
{
    //do stuff here
}

这篇关于如何判断控制器何时从后台恢复?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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