Class

UIApplication

The centralized point of control and coordination for apps running in iOS.

Declaration

class UIApplication : UIResponder

Overview

Every iOS app has exactly one instance of UIApplication (or, very rarely, a subclass of UIApplication). When an app is launched, the system calls the UIApplicationMain(_:_:_:_:) function; among its other tasks, this function creates a Singleton UIApplication object. Thereafter you access the object by calling the shared class method.

A major role of your app’s application object is to handle 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) and through those can 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 openURL(_:) 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:

Subclassing Notes

Most apps do not 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, dispatch it back to the system by calling [super sendEvent:event] after you handle the event. Intercepting events is only rarely required and you should avoid it if possible.

Topics

Getting the App Instance

class var shared: UIApplication

Returns the singleton app instance.

Managing the App's Behavior

var delegate: UIApplicationDelegate?

The delegate of the app object.

protocol UIApplicationDelegate

A set of methods that you use to manage shared behaviors for your app.

Registering for Remote Notifications

func registerForRemoteNotifications()

Register to receive remote notifications via Apple Push Notification service.

func unregisterForRemoteNotifications()

Unregister for all remote notifications received via Apple Push Notification service.

var isRegisteredForRemoteNotifications: Bool

A Boolean indicating whether the app is currently registered for remote notifications.

Getting the Application State

var applicationState: UIApplication.State

The runtime state of the app.

enum UIApplication.State

The running states of an app

Getting Scene Information

var supportsMultipleScenes: Bool

A Boolean value indicating whether the app may display multiple scenes simultaneously.

Beta
var connectedScenes: Set<UIScene>

The app's currently connected scenes.

Beta
var openSessions: Set<UISceneSession>

The sessions whose scenes are either currently active or archived by the system.

Beta

Creating, Destroying, and Updating Scenes

func requestSceneSessionDestruction(UISceneSession, options: UISceneDestructionRequestOptions?, errorHandler: ((Error) -> Void)?)

Asks the system to dismiss an existing scene and remove it from the app switcher.

Beta
func requestSceneSessionRefresh(UISceneSession)

Asks the system to update any system UI associated with the specified scene.

Beta

Managing Background Execution

var backgroundRefreshStatus: UIBackgroundRefreshStatus

Indicates whether the app can refresh content when running in the background.

enum UIBackgroundRefreshStatus

Constants indicating whether background execution is enabled for the app.

class let backgroundRefreshStatusDidChangeNotification: NSNotification.Name

Posted when the app’s status for downloading content in the background changes.

func beginBackgroundTask(withName: String?, expirationHandler: (() -> Void)?) -> UIBackgroundTaskIdentifier

Marks the beginning of a new long-running background task with the specified name.

func endBackgroundTask(UIBackgroundTaskIdentifier)

Marks the end of a specific long-running background task.

struct UIBackgroundTaskIdentifier

A unique token that identifies a request to run in the background.

var backgroundTimeRemaining: TimeInterval

The amount of time the app has to run in the background.

Fetching Content in the Background

class let backgroundFetchIntervalMinimum: TimeInterval

The smallest fetch interval supported by the system.

class let backgroundFetchIntervalNever: TimeInterval

A fetch interval large enough to prevent fetch operations from occurring.

Opening a URL Resource

func canOpenURL(URL) -> Bool

Returns a Boolean value indicating whether an app is available to handle a URL scheme.

class let openSettingsURLString: String

Used to create a URL that you can pass to the openURL(_:) method. When you open the URL built from this string, the system launches the Settings app and displays the app’s custom settings, if it has any.

Managing the App Idle Timer

var isIdleTimerDisabled: Bool

A Boolean value that controls whether the idle timer is disabled for the app.

Managing the State Restoration Behavior

func extendStateRestoration()

Tells the app that your code is restoring state asynchronously.

func completeStateRestoration()

Tells the app that your code has finished any asynchronous state restoration.

func ignoreSnapshotOnNextApplicationLaunch()

Prevents the app from using the recent snapshot image during the next launch cycle.

class func registerObject(forStateRestoration: UIStateRestoring, restorationIdentifier: String)

Registers a custom object for use with the state restoration system.

Managing Home Screen Quick Actions for 3D Touch

var shortcutItems: [UIApplicationShortcutItem]?

The Home screen dynamic quick actions for your app; available on devices that support 3D Touch.

Determining the Availability of Protected Content

var isProtectedDataAvailable: Bool

A Boolean value indicating whether content protection is active.

class let protectedDataDidBecomeAvailableNotification: NSNotification.Name

Posted when the protected files become available for your code to access.

class let protectedDataWillBecomeUnavailableNotification: NSNotification.Name

Posted shortly before protected files are locked down and become inaccessible.

Registering for Remote Control Events

func beginReceivingRemoteControlEvents()

Tells the app to begin receiving remote-control events.

func endReceivingRemoteControlEvents()

Tells the app to stop receiving remote-control events.

Controlling App Appearance

var userInterfaceLayoutDirection: UIUserInterfaceLayoutDirection

Returns the layout direction of the user interface.

enum UIUserInterfaceLayoutDirection

Specifies the directional flow of the user interface.

Controlling and Handling Events

func sendEvent(UIEvent)

Dispatches an event to the appropriate responder objects in the app.

func sendAction(Selector, to: Any?, from: Any?, for: UIEvent?) -> Bool

Sends an action message identified by selector to a specified target.

func beginIgnoringInteractionEvents()

Tells the receiver to suspend the handling of touch-related events.

Deprecated
func endIgnoringInteractionEvents()

Tells the receiver to resume the handling of touch-related events.

Deprecated
var isIgnoringInteractionEvents: Bool

A Boolean value that indicates whether the receiver is ignoring events initiated by touches on the screen.

Deprecated
var applicationSupportsShakeToEdit: Bool

A Boolean value that determines whether shaking the device displays the undo-redo user interface.

Managing the App's Icon

var applicationIconBadgeNumber: Int

The number currently set as the badge of the app icon in Springboard.

var supportsAlternateIcons: Bool

A Boolean value indicating whether the app is allowed to change its icon.

var alternateIconName: String?

The name of the icon being displayed for the app.

Getting App Windows

var keyWindow: UIWindow?

The app's key window.

Deprecated
var windows: [UIWindow]

The app's visible and hidden windows.

Getting the Font Sizing Preference

var preferredContentSizeCategory: UIContentSizeCategory

The font sizing option preferred by the user.

struct UIContentSizeCategory

Constants indicating the preferred size of your content.

static let newValueUserInfoKey: String

A key whose value is an NSString object reflecting the new value of the preferredContentSizeCategory property.

static let didChangeNotification: NSNotification.Name

Posted when the user changes the preferred content size setting.

Managing the Default Interface Orientations

func supportedInterfaceOrientations(for: UIWindow?) -> UIInterfaceOrientationMask

Returns the default set of interface orientations to use for the view controllers in the specified window.

Responding to Status Bar Changes

enum UIStatusBarStyle

The style of the device’s status bar.

enum UIStatusBarAnimation

The animation applied to the status bar as it is hidden or made visible.

Tracking Controls in the Run Loop

static let tracking: RunLoop.Mode

The mode set while tracking in controls takes place.

Detecting an App Snapshot

class let userDidTakeScreenshotNotification: NSNotification.Name

Posted when the user presses the Home and Lock buttons to take a screenshot.

Deprecated Symbols

func setMinimumBackgroundFetchInterval(TimeInterval)

Specifies the minimum amount of time that must elapse between background fetch operations.

Deprecated
var statusBarOrientationAnimationDuration: TimeInterval

The animation duration in seconds for the status bar during a 90 degree orientation change.

Deprecated
class let didChangeStatusBarFrameNotification: NSNotification.Name

Posted when the frame of the status bar changes.

Deprecated
class let didChangeStatusBarOrientationNotification: NSNotification.Name

Posted when the orientation of the app’s user interface changes.

Deprecated
class let willChangeStatusBarOrientationNotification: NSNotification.Name

Posted when the app is about to change the orientation of its interface.

Deprecated
class let willChangeStatusBarFrameNotification: NSNotification.Name

Posted when the app is about to change the frame of the status bar.

Deprecated
class let statusBarOrientationUserInfoKey: String

A key whose value is an NSNumber object that encapsulates a UIInterfaceOrientation value indicating the current orientation (see UIInterfaceOrientation). This key is used with didChangeStatusBarOrientationNotification and willChangeStatusBarOrientationNotification notifications.

Deprecated
class let statusBarFrameUserInfoKey: String

A key whose value is an NSValue object that encapsulates a CGRect structure expressing the location and size of the new status bar frame. This key is used with didChangeStatusBarFrameNotification and willChangeStatusBarFrameNotification notifications.

Deprecated
var statusBarFrame: CGRect

The frame rectangle defining the area of the status bar.

Deprecated
var isNetworkActivityIndicatorVisible: Bool

A Boolean value that turns an indicator of network activity on or off.

Deprecated
let UIMinimumKeepAliveTimeout: TimeInterval

The minimum amount of time (measured in seconds) an app may run a critical background task in the background.

Deprecated
func registerUserNotificationSettings(UIUserNotificationSettings)

Registers your preferred options for notifying the user.

Deprecated
var currentUserNotificationSettings: UIUserNotificationSettings?

Returns the user notification settings for the app.

Deprecated
struct UIRemoteNotificationType

Constants indicating the types of notifications the app may display to the user.

Deprecated
func openURL(URL) -> Bool

Attempts to open the resource at the specified URL.

Deprecated
func scheduleLocalNotification(UILocalNotification)

Schedules a local notification for delivery at its encapsulated date and time.

Deprecated
func presentLocalNotificationNow(UILocalNotification)

Presents a local notification immediately.

Deprecated
func cancelLocalNotification(UILocalNotification)

Cancels the delivery of the specified scheduled local notification.

Deprecated
func cancelAllLocalNotifications()

Cancels the delivery of all scheduled local notifications.

Deprecated
var scheduledLocalNotifications: [UILocalNotification]?

All currently scheduled local notifications.

Deprecated
func setNewsstandIconImage(UIImage?)

Sets the icon of a Newsstand app to an image depicting the current issue of a publication.

Deprecated
func setKeepAliveTimeout(TimeInterval, handler: (() -> Void)?) -> Bool

Configures a periodic handler for VoIP apps in older versions of iOS.

Deprecated
func clearKeepAliveTimeout()

Removes a previously installed periodic handler block.

Deprecated
func setStatusBarHidden(Bool, with: UIStatusBarAnimation)

Hides or shows the status bar, optionally animating the transition.

Deprecated
var isStatusBarHidden: Bool

A Boolean value that determines whether the status bar is hidden.

Deprecated
func setStatusBarStyle(UIStatusBarStyle, animated: Bool)

Sets the style of the status bar, optionally animating the transition to the new style.

Deprecated
var statusBarStyle: UIStatusBarStyle

The current style of the status bar.

Deprecated
func setStatusBarOrientation(UIInterfaceOrientation, animated: Bool)

Sets the app's status bar to the specified orientation, optionally animating the transition.

Deprecated
var statusBarOrientation: UIInterfaceOrientation

The current orientation of the app's status bar.

Deprecated
func registerForRemoteNotifications(matching: UIRemoteNotificationType)

Register to receive remote notifications of the specified types via Apple Push Notification service.

Deprecated
func enabledRemoteNotificationTypes() -> UIRemoteNotificationType

Returns the types of notifications the app accepts.

Deprecated

See Also

Life Cycle

Managing Your App's Life Cycle

Respond to system notifications when your app is in the foreground or background, and handle other significant system-related events.

Responding to the Launch of Your App

Initialize your app’s data structures, prepare your app to run, and respond to any launch-time requests from the system.

protocol UIApplicationDelegate

A set of methods that you use to manage shared behaviors for your app.

Scenes

Manage multiple instances of your app’s UI simultaneously, and direct resources to the appropriate instance of your UI.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software