Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

applicationWillEnterForeground never called

Hey there, I'm trying Multitasking in the Simulator (I only have a 2nd gen iPod and an iPad) and I'm still having some problems. My testing methods look like this:

- (void)applicationDidBecomeActive:(UIApplication *)application {
 NSLog(@"Entering %s",__FUNCTION__);

 if (enteredFromBackground) {
  NSLog(@"Entering from Background");
  enteredFromBackground = NO;
 }
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
 NSLog(@"Entering %s",__FUNCTION__);

 enteredFromBackground = YES;
}

Unforntunately, I'm not seeing the NSLog from applicationWillEnterForeground, that's why I added the line to show me something in applicationDidBecomeActive. All I get is the

2010-11-20 15:58:12.796 iBeat[45997:207] Entering -[AppDelegate_Shared applicationDidEnterBackground:]
2010-11-20 15:58:18.160 iBeat[45997:207] Entering -[AppDelegate_Shared applicationDidBecomeActive:]
like image 560
Bersaelor Avatar asked Nov 20 '10 14:11

Bersaelor


People also ask

When applicationWillEnterForeground is called?

applicationWillEnterForeground: is called after application: didFinishLaunchingWithOptions : or if your app becomes active again after receiving a phone call or other system interruption. applicationDidBecomeActive: is called after applicationWillEnterForeground: to finish up the transition to the foreground.

How do I keep IOS apps running in foreground?

To keep apps running in the background on iPhone, you can turn on the background app refresh feature. Go to Settings, General, Background App Refresh and turn it on. In the following apps, toggle on the ones you want to keep running.


2 Answers

After having this problem in iOS 13, I found out that I was waiting for applicationWillEnterForeground(_ application: UIApplication) to be called instead of sceneWillEnterForeground(_ scene: UIScene).

For more information, read this answer:

enter link description here

like image 178
Laura Corssac Avatar answered Oct 06 '22 22:10

Laura Corssac


Finally I found my problem! Since I have a universal Application, I have an Appdelegate_Shared, an Appdelegate_iPhone, and an Appdelegate_iPad. I had an empty implementation of "applicationWillEnterForeground" in the two subclasses but didn't call super!

And then I wondered why the method in Appdelegate_Shared never got called o.O

like image 37
Bersaelor Avatar answered Oct 06 '22 20:10

Bersaelor