applicationWillEnterForeground never called
Asked Answered
L

3

9

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:]
Lorielorien answered 20/11, 2010 at 14:59 Comment(1)
The accepted answer is not my scenario and I still have this problem. I have an iOS app which doesn't adopt scenes. In iOS 16.2 simulator, applicationWillEnterForeground is never invoked. It's counterpart, applicationWillEnterBackground is invoked consistently.Houlihan
L
6

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

Lorielorien answered 24/1, 2011 at 10:26 Comment(0)
R
12

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

Ratify answered 3/6, 2020 at 6:52 Comment(1)
I have an iOS app which doesn't adopt scenes. But still, appWillEnterForeground(_:) was never invoked.Houlihan
L
6

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

Lorielorien answered 24/1, 2011 at 10:26 Comment(0)
B
2

In 2023:

  1. Remove scene manifest completely from Info.plist.
  2. Add @UIApplicationMain right before your AppDelegate declaration.
  3. Initialize UIWindow and set it to window property in AppDelegate
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    var window: UIWindow?
    // other code...
}

At least, it's helped me. Cheers.

P.S. Swift 5.9, Xcode 15.0.1, Device Target iOS 17.0;

Balefire answered 6/12, 2023 at 14:55 Comment(2)
This is going in the wrong direction. You should be using scenes, not removing them.Vorster
@Vorster Well, it sounds obviously correct what you've said, but all I did is just follow Apple's Placing Objects and Handling 3D Interaction step by step to get better understanding how it works talking about interacting with objects in ARKit. And at the same time just decided to leave a reply here for the question. But yeah, I agree with you.Balefire

© 2022 - 2024 — McMap. All rights reserved.