UIApplication
The centralized point of control and coordination for apps running in iOS.
Declaration
@MainActor class UIApplicationMentioned in
Overview
Every iOS app has exactly one instance of UIApplication (or, very rarely, a subclass of UIApplication). When an app launches, the system calls the UIApplicationMain(_:_:_:_:) function. Among its other tasks, this function creates a singleton UIApplication object that you access using shared.
Your app’s application object handles the initial routing of incoming user events. It dispatches action messages forwarded to it by control objects (instances of the UIControl class) to appropriate target objects. The application object maintains a list of open windows (UIWindow objects), which it can use to retrieve any of the app’s UIView objects.
The UIApplication class defines a delegate that conforms to the UIApplicationDelegate protocol and must implement some of the protocol’s methods. The application object informs the delegate of significant runtime events—for example, app launch, low-memory warnings, and app termination—giving it an opportunity to respond appropriately.
Apps can cooperatively handle a resource, such as an email or an image file, through the open(_:options:completionHandler:) method. For example, an app that calls this method with an email URL causes the Mail app to launch and display the message.
The APIs in this class allow you to manage device-specific behavior. Use your UIApplication object to do the following:
Temporarily suspend incoming touch events (beginIgnoringInteractionEvents())
Register for remote notifications (registerForRemoteNotifications())
Trigger the undo-redo UI (applicationSupportsShakeToEdit)
Determine whether there is an installed app registered to handle a URL scheme (canOpenURL(_:))
Extend the execution of the app so that it can finish a task in the background (beginBackgroundTask(expirationHandler:) and beginBackgroundTask(withName:expirationHandler:))
Schedule and cancel local notifications (scheduleLocalNotification(_:) and cancelLocalNotification(_:))
Coordinate the reception of remote-control events (beginReceivingRemoteControlEvents() and endReceivingRemoteControlEvents())
Perform app-level state restoration tasks (methods in the Managing state restoration task group)
Subclassing notes
Most apps don’t need to subclass UIApplication. Instead, use an app delegate to manage interactions between the system and the app.
If your app must handle incoming events before the system does—a very rare situation—you can implement a custom event or action dispatching mechanism. To do this, subclass UIApplication and override the sendEvent(_:) and/or the sendAction(_:to:from:for:) methods. For every event you intercept, after you handle the event, dispatch it back to the system by calling:
super.sendEvent(event)Intercepting events is only rarely required and you should avoid it if possible.
Topics
Accessing the shared application
Configuring your app’s behavior
Registering for remote notifications
registerForRemoteNotifications()unregisterForRemoteNotifications()isRegisteredForRemoteNotifications
Getting the application state
Getting scene information
Managing a scene’s life cycle
activateSceneSession(for:errorHandler:)requestSceneSessionDestruction(_:options:errorHandler:)requestSceneSessionRefresh(_:)UISceneSessionActivationRequestUIScene.ActivationRequestOptionsUISceneDestructionRequestOptions
Managing background tasks
backgroundRefreshStatusUIBackgroundRefreshStatusbackgroundRefreshStatusDidChangeNotificationbeginBackgroundTask(withName:expirationHandler:)beginBackgroundTask(expirationHandler:)endBackgroundTask(_:)UIBackgroundTaskIdentifierbackgroundTimeRemaining
Fetching content in the background
Opening a URL resource
Deep linking to custom settings
openSettingsURLStringopenNotificationSettingsURLStringUIApplicationOpenNotificationSettingsURLStringopenDefaultApplicationsSettingsURLString
Managing the app’s idle timer
Managing state restoration
extendStateRestoration()completeStateRestoration()ignoreSnapshotOnNextApplicationLaunch()registerObject(forStateRestoration:restorationIdentifier:)
Providing an app’s shortcut items
Accessing protected content
isProtectedDataAvailableprotectedDataDidBecomeAvailableNotificationprotectedDataWillBecomeUnavailableNotification
Receiving remote control events
Accessing the layout direction
Controlling and handling events
Managing the app’s icon
Managing the preferred content size
preferredContentSizeCategoryUIContentSizeCategoryUIContentSizeCategoryAdjustingdidChangeNotificationnewValueUserInfoKey
Specifying the supported interface orientations
Tracking controls in the run loop
Detecting screenshots
Discovering if your app is the default app in a category
Deprecated
Structures
UIApplication.BackgroundRefreshStatusDidChangeMessageUIApplication.DidBecomeActiveMessageUIApplication.DidEnterBackgroundMessageUIApplication.DidFinishLaunchingMessageUIApplication.DidReceiveMemoryWarningMessageUIApplication.ProtectedDataDidBecomeAvailableMessageUIApplication.ProtectedDataWillBecomeUnavailableMessageUIApplication.SignificantTimeChangeMessageUIApplication.UserDidTakeScreenshotMessageUIApplication.WillEnterForegroundMessageUIApplication.WillResignActiveMessageUIApplication.WillTerminateMessage