如何判断控制器何时从后台恢复?

Rap*_*eta 10 iphone multitasking ios4

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

提前致谢

Elf*_*red 20

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

- (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
}
Run Code Online (Sandbox Code Playgroud)