The app transitions through the following states in its life cycle:
- Not Running:
- The app is not launched and not running.
- Inactive:
- The app is running in the foreground but not receiving user input.
- Occurs during temporary interruptions (e.g., an incoming phone call or notification).
- Active:
- The app is running in the foreground and actively receiving user input.
- Background:
- The app is no longer visible but still executing code.
- Used for tasks like saving data, fetching content, or playing audio.
- Suspended:
- The app is in memory but not executing any code.
- It can be terminated by the system if memory is needed.
The application life cycle is managed by the AppDelegate and SceneDelegate.
1.application(_:didFinishLaunchingWithOptions:)
- Called when the app is launched.
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Initialization code
print("App did finish launching")
return true
}
2.applicationDidBecomeActive(_:)
- Called when the app becomes active (foreground and interactive).
func applicationDidBecomeActive(_ application: UIApplication) {
print("App became active")
}
3.applicationWillResignActive(_:)
- Called when the app is about to go inactive.
func applicationWillResignActive(_ application: UIApplication) {
print("App will resign active")
}
4.applicationDidEnterBackground(_:)
Called when the app enters the background.
func applicationDidEnterBackground(_ application: UIApplication) {
print("App entered background")
}
5.applicationWillEnterForeground(_:)
Called as the app transitions from background to foreground.
func applicationWillEnterForeground(_ application: UIApplication) {
print("App will enter foreground")
}
6.applicationWillTerminate(_:)
Called when the app is about to terminate.
func applicationWillTerminate(_ application: UIApplication) {
print("App will terminate")
}