init(), .onAppear and .onChange(of: scenePhase) Not Working when Opening App After Being Quitted

The following code segments run when building and running the app, or after going home and re-opening the app, but now when quitting the app and re-opening it again. What code can do that?

init() {
    print("test")
}
.onAppear {
    print("test)
}
.onChange(of: scenePhase) { _, newValue in
    print(newValue)
}

The following code segments run when building and running the app, or after going home and re-opening the app, but now when quitting the app and re-opening it again. What code can do that?

Please be more precise in explaining the use case and what they mean exactly

  • after going home and re-opening: what do you do exactly
  • when you quit: what do you do precisely ? What do you get ? What did you expect ?
  • explain what you get printed for each of the cases.

Note: you should have more discriminant print:

init() {
    print("init test")
}
.onAppear {
    print("onAppear test)
}
.onChange(of: scenePhase) { _, newValue in
    print("onChange \(newValue)")
}

Once you clarify the question please include a code snippet that run and compiles. That way we're able to reproduce the issue.

Below is compilable code:

struct ContentView: View {
    var body: some View {
        Text("Text")
            .onAppear() {
                print("test")
            }
    }
}

"test" is printed in the console after a new build, and when I go to the Home Screen and return to the app, but if I swipe up from the bottom, and then swipe up from the menu of apps to close the app, it does not print upon opening the app again. What would be an example of code that does run under the circumstance of fully quitting the app and opening it again?

init(), .onAppear and .onChange(of: scenePhase) Not Working when Opening App After Being Quitted
 
 
Q