3

I am writing an application using phonegap for iOS. I am trying to show splash screen when application enters to background.

(void)applicationWillResignActive:(UIApplication *)application [...]

In applicationWillResignActive: I am calling a JavaScript function and using cordova's method cordova.exec(null,null, "SplashScreen, "show", []) to show splash screen. But it seems like, this is not working.

When I resume the app, the application brings the previous state first and then switches to splash screen, but I want to show the splash screen when the app resumes. How can I accomplish that?

Rex Nihilo
  • 604
  • 2
  • 7
  • 16
ananth85
  • 137
  • 2
  • 12

2 Answers2

4

Got this working:

- (void) applicationWillResignActive:(UIApplication *)application {
  //Call to JS to change to splash
 [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.02
}

Allow the current runloop to run for a brief moment

For more information on the answer please check the below link:

The exact moment iOS takes the view snapshot when entering background?

Community
  • 1
  • 1
ananth85
  • 137
  • 2
  • 12
0

As you've experienced, the actual view hierarchy will not be modified until the app resumes activity. Try setting a property/variable in -applicationWillResignActive: that indicates you should show the splash screen when the app becomes active again, then actually show it immediately in -applicationDidBecomeActive:

Matt
  • 1,586
  • 8
  • 12
  • Matt, Thanks for the reply. I tried your suggestion. But when the app is brought to foreground i still the see previous state first and then it switches to splash. – ananth85 Oct 22 '12 at 21:39
  • Does your "show" method show it animated? Because, you might try to make the change happen without animation, and force a layout/display. Also, if you're having trouble doing this kind of think in the app delegate methods, you could try putting it in viewWillAppear on your root view controller. Sorry for the false lead. – Matt Oct 22 '12 at 22:34