Class

UIApplication

The UIApplication class provides a centralized point of control and coordination for apps running in iOS. Every app has exactly one instance of UIApplication (or, very rarely, a subclass of UIApplication). When an app is launched, the system calls the UIApplication​Main(_:​_:​_:​_:​) function; among its other tasks, this function creates a Singleton UIApplication object. Thereafter you access the object by calling the shared class method.

Overview

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 UIApplication​Delegate 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​URL(_:​) 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 send​Event(_:​) and/or the send​Action(_:​to:​from:​for:​) methods. For every event you intercept, dispatch it back to the system by calling [super send​Event:​event] after you handle the event. Intercepting events is only rarely required and you should avoid it if possible.

Symbols

Getting the App Instance

class var shared:​ UIApplication

Returns the singleton app instance.

Getting the App Delegate

var delegate:​ UIApplication​Delegate?

The delegate of the app object.

Getting App Windows

var key​Window:​ UIWindow?

The app's key window.

var windows:​ [UIWindow]

The app's visible and hidden windows.

Controlling and Handling Events

func send​Event(UIEvent)

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

func send​Action(Selector, to:​ Any?, from:​ Any?, for:​ UIEvent?)

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

func begin​Ignoring​Interaction​Events()

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

func end​Ignoring​Interaction​Events()

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

var is​Ignoring​Interaction​Events:​ Bool

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

var application​Supports​Shake​To​Edit:​ Bool

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

Opening a URL Resource

func can​Open​URL(URL)

Returns a Boolean value indicating whether or not the URL’s scheme can be handled by some app installed on the device.

Configuring the User Notification Settings

func register​User​Notification​Settings(UIUser​Notification​Settings)

Registers your preferred options for notifying the user.

Registering for Remote Notifications

func register​For​Remote​Notifications()

Register to receive remote notifications via Apple Push Notification service.

func unregister​For​Remote​Notifications()

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

var is​Registered​For​Remote​Notifications:​ Bool

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

Managing Background Execution

var background​Time​Remaining:​ Time​Interval

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

var background​Refresh​Status:​ UIBackground​Refresh​Status

The ability of the app to be launched into the background so that it can perform background behaviors.

func set​Minimum​Background​Fetch​Interval(Time​Interval)

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

func begin​Background​Task(with​Name:​ String?, expiration​Handler:​ (() -> Void)? = nil)

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

func begin​Background​Task(expiration​Handler:​ (() -> Void)? = nil)

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

func end​Background​Task(UIBackground​Task​Identifier)

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

Managing the App Idle Timer

var is​Idle​Timer​Disabled:​ Bool

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

Managing the State Restoration Behavior

func extend​State​Restoration()

Tells the app that your code is restoring state asynchronously.

func complete​State​Restoration()

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

func ignore​Snapshot​On​Next​Application​Launch()

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

Managing Home Screen Quick Actions for 3D Touch

var shortcut​Items:​ [UIApplication​Shortcut​Item]?

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

Determining the Availability of Protected Content

var is​Protected​Data​Available:​ Bool

A Boolean value indicating whether content protection is active.

Registering for Remote Control Events

func begin​Receiving​Remote​Control​Events()

Tells the app to begin receiving remote-control events.

func end​Receiving​Remote​Control​Events()

Tells the app to stop receiving remote-control events.

Controlling App Appearance

var status​Bar​Frame:​ CGRect

The frame rectangle defining the area of the status bar.

var is​Network​Activity​Indicator​Visible:​ Bool

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

Managing the App's Icon

var application​Icon​Badge​Number:​ Int

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

var supports​Alternate​Icons:​ Bool

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

Beta
var alternate​Icon​Name:​ String?

The name of the icon being displayed for the app.

Beta

Getting the Font Sizing Preference

Managing the Default Interface Orientations

func supported​Interface​Orientations(for:​ UIWindow?)

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

Managing Status Bar Orientation

var status​Bar​Orientation​Animation​Duration:​ Time​Interval

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

Deprecated Methods

func open​URL(URL)

Attempts to open the resource at the specified URL.

Deprecated
func schedule​Local​Notification(UILocal​Notification)

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

Deprecated
func present​Local​Notification​Now(UILocal​Notification)

Presents a local notification immediately.

Deprecated
func cancel​Local​Notification(UILocal​Notification)

Cancels the delivery of the specified scheduled local notification.

Deprecated
func cancel​All​Local​Notifications()

Cancels the delivery of all scheduled local notifications.

Deprecated
var scheduled​Local​Notifications:​ [UILocal​Notification]?

All currently scheduled local notifications.

Deprecated
func set​Newsstand​Icon​Image(UIImage?)

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

Deprecated
func set​Keep​Alive​Timeout(Time​Interval, handler:​ (() -> Void)? = nil)

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

Deprecated
func clear​Keep​Alive​Timeout()

Removes a previously installed periodic handler block.

Deprecated
func set​Status​Bar​Hidden(Bool, with:​ UIStatus​Bar​Animation)

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

Deprecated
var is​Status​Bar​Hidden:​ Bool

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

Deprecated
func set​Status​Bar​Style(UIStatus​Bar​Style, animated:​ Bool)

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

Deprecated
var status​Bar​Style:​ UIStatus​Bar​Style

The current style of the status bar.

Deprecated
func set​Status​Bar​Orientation(UIInterface​Orientation, animated:​ Bool)

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

Deprecated
var status​Bar​Orientation:​ UIInterface​Orientation

The current orientation of the app's status bar.

Deprecated
func register​For​Remote​Notifications(matching:​ UIRemote​Notification​Type)

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

Deprecated
func enabled​Remote​Notification​Types()

Returns the types of notifications the app accepts.

Deprecated

Constants

UIApplication​State

The running states of an app

UIBackground​Task​Identifier

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

Background Task Constants

Constants used when running in the background.

UIBackground​Fetch​Result

Constants that indicate the result of a background fetch operation.

Fetch Intervals

Constants indicating fetch intervals for background downloads.

UIBackground​Refresh​Status

Constants indicating whether background execution is enabled for the app.

UIRemote​Notification​Type

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

Deprecated
UIInterface​Orientation

The orientation of the app's user interface.

UIInterface​Orientation​Mask

These constants are mask bits for specifying a view controller’s supported interface orientations.

UIUser​Interface​Layout​Direction

Specifies the directional flow of the user interface.

UIStatus​Bar​Style

The style of the device’s status bar.

UIStatus​Bar​Animation

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

Settings Launch URL

Constant used to open the app’s settings.

URL Options
User​Info Dictionary Keys

Keys used to access values in the user​Info dictionary of some UIApplication-posted notifications.

Content Size Category Constants

Constants that indicate the user’s preferred font size.

Accessibility Content Size Category Constants

Constants that indicate the preferred font sizes when accessibility is enabled.

Key for Content Size Change Notifications

Key identifying the new content size category.

Extension Point Identifier Constants

Constants that identify extension points you want to disallow in your app.

Run Loop Mode for Tracking

Mode while tracking in controls is taking place.

Exceptions

The following constant defines an exception that can be thrown by the app.

Notifications

All UIApplication notifications are posted by the app instance returned by shared.

static let UIApplication​Background​Refresh​Status​Did​Change:​ NSNotification.Name

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

static let UIApplication​Did​Change​Status​Bar​Orientation:​ NSNotification.Name

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

static let UIApplication​Did​Finish​Launching:​ NSNotification.Name

Posted immediately after the app finishes launching.

static let UIApplication​Did​Receive​Memory​Warning:​ NSNotification.Name

Posted when the app receives a warning from the operating system about low memory availability.

static let UIApplication​Protected​Data​Did​Become​Available:​ NSNotification.Name

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

static let UIApplication​Protected​Data​Will​Become​Unavailable:​ NSNotification.Name

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

static let UIApplication​Significant​Time​Change:​ NSNotification.Name

Posted when there is a significant change in time, for example, change to a new day (midnight), carrier time update, and change to or from daylight savings time.

static let UIApplication​User​Did​Take​Screenshot:​ NSNotification.Name

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

static let UIApplication​Will​Change​Status​Bar​Orientation:​ NSNotification.Name

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

static let UIApplication​Will​Change​Status​Bar​Frame:​ NSNotification.Name

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

static let UIApplication​Will​Enter​Foreground:​ NSNotification.Name

Posted shortly before an app leaves the background state on its way to becoming the active app.

static let UIApplication​Will​Resign​Active:​ NSNotification.Name

Posted when the app is no longer active and loses focus.

static let UIContent​Size​Category​Did​Change:​ NSNotification.Name

Posted when the user changes the preferred content size setting.

Relationships

Inherits From

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