App and environment
Manage life-cycle events and your app’s UI scenes, and get information about traits and the environment in which your app runs.
Overview
From the moment a person opens your app, a number of things can happen that your app may need to handle or adjust to, such as switching to another app, receiving a call, switching Dark Mode on or off, or rotating the device. UIKit communicates some changes as life cycle events, and others as trait changes.
Your app displays its interface in one or more scenes. On iPhone, your app only shows one scene. On iPad, Mac, and Apple Vision Pro, a person can create and manage multiple instances of your app’s user interface simultaneously, in different windows or side by side. Each instance of your UI displays different content, or displays the same content in a different way. For example, a person can display one instance of the Calendar app showing a specific day, and another showing an entire month.
UIKit communicates details about the current environment using trait collections, which reflect a combination of device settings, interface settings, and user preferences. For example, you use traits to detect whether Dark Mode is active for the current view or view controller. Consult Adapting your app when traits change when you want to customize your app based on the current environment, and update it based on trait changes. Review Providing data to the view hierarchy with custom traits to share data in your view hierarchy using custom traits.
In iOS 18 and later, combine Swift Observation with UIKit’s automatic tracking to update your views automatically when model data changes. Mark your model classes with the @Observable macro, then reference observable properties in supported methods. Then, UIKit automatically tracks property access and updates your views when those properties change.
Access device-specific information like battery state, proximity sensor data, and device orientation through UIDevice, and check status bar configuration using UIStatusBarManager.
Topics
Life cycle
Managing your app’s life cycleResponding to the launch of your appUIApplicationUIApplicationDelegateScenes
Device environment
Data observation
Adaptivity and traits
iPad, Mac, and Apple Vision Pro
Building a desktop-class iPad appElevating your iPad app with a tab bar and sidebarSupporting desktop-class features in your iPad appMultitasking on iPad, Mac, and Apple Vision Pro