2

I have a Tab bar app with 3 view controllers and I use "viewWillAppear" to detect which view is opend.

When I close the app, it still works "in the background" and when I open the app again "viewWillAppear" is not detecting this opening.

Is there any other option to detect this opening? Thanks

iWizard
  • 6,816
  • 19
  • 67
  • 103

4 Answers4

8

You can observe the UIApplicationWillEnterForegroundNotification or implement applicationWillEnterForeground: in your app delegate.

omz
  • 53,243
  • 5
  • 129
  • 141
5

Firstly, You should see the necessary delegation method in UIApplicationDelegate

  • When you close application that currently open, It will call this method:

    - (void)applicationDidEnterBackground:(UIApplication *)application

  • After the application has been closed but still in dock, you open them again. In the transition state before entering the application, It will call this method:

    - (void)applicationWillEnterForeground:(UIApplication *)application

  • When the application completely presented on previous state before you closed them. It finally call thid method:

    - (void)applicationDidBecomeActive:(UIApplication *)application

If you would like to do something in viewWillAppear you should implement in applicationDidBecomeActive to send some message to your current view or other to do what do you want to do after application became actived.

Sakares
  • 606
  • 12
  • 31
  • can you tell me please or give mi a link to an example of implementing this? – iWizard May 06 '12 at 11:19
  • found it here: http://stackoverflow.com/questions/4919950/applicationwillenterforeground-reload-data-from-viewcontroller Thank's everyone for help – iWizard May 06 '12 at 11:31
  • Is it possible to refresh start ViewControoler in applicationWillEnterForeground? If yes tell me pls how. – iWizard May 07 '12 at 08:40
  • I'm not sure about implementing in applicationWillEnterForeground. If you have a complex refresh code it may cause some problem. For me, I prefer to fire the refresh code in applicationDidBecomeActive. But you can try both method for what is the best for your application. – Sakares May 07 '12 at 08:46
1

When your app is resumed from the background, it will receive the applicationWillEnterForground: method. It'll get the applicationDidEnterBackground: when it is suspended too.

Jasarien
  • 58,279
  • 31
  • 157
  • 188
0
- (void)applicationWillEnterForeground:(UIApplication *)application {
NSLog(@"app will enter foreground");
[viewController refresh:NULL];
}

i think this will work. write this in your app delegate

Enea Dume
  • 3,014
  • 3
  • 21
  • 36