Class

UIApplication

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

Declaration

@interface 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 sharedApplication 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:forEvent: 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

sharedApplication

Returns the singleton app instance.

Managing the App's Behavior

delegate

The delegate of the app object.

UIApplicationDelegate

A set of methods that are called by the singleton UIApplication object in response to important events in the lifetime of your app.

Registering for Remote Notifications

- registerForRemoteNotifications

Register to receive remote notifications via Apple Push Notification service.

- unregisterForRemoteNotifications

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

registeredForRemoteNotifications

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

Getting the Application State

applicationState

The runtime state of the app.

UIApplicationState

The running states of an app

Managing Background Execution

backgroundRefreshStatus

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

UIBackgroundRefreshStatus

Constants indicating whether background execution is enabled for the app.

- beginBackgroundTaskWithName:expirationHandler:

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

- beginBackgroundTaskWithExpirationHandler:

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

- endBackgroundTask:

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

UIBackgroundTaskIdentifier

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

backgroundTimeRemaining

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

Fetching Content in the Background

- setMinimumBackgroundFetchInterval:

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

UIApplicationBackgroundFetchIntervalMinimum

The smallest fetch interval supported by the system.

UIApplicationBackgroundFetchIntervalNever

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

UIMinimumKeepAliveTimeout

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

Opening a URL Resource

- openURL:options:completionHandler:

Attempts to open the resource at the specified URL asynchronously.

- canOpenURL:

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

UIApplicationOpenExternalURLOptionsKey

Options for opening a URL.

UIApplicationOpenSettingsURLString

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

idleTimerDisabled

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

Managing the State Restoration Behavior

- extendStateRestoration

Tells the app that your code is restoring state asynchronously.

- completeStateRestoration

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

- ignoreSnapshotOnNextApplicationLaunch

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

+ registerObjectForStateRestoration:restorationIdentifier:

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

Managing Home Screen Quick Actions for 3D Touch

shortcutItems

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

Determining the Availability of Protected Content

protectedDataAvailable

A Boolean value indicating whether content protection is active.

Registering for Remote Control Events

- beginReceivingRemoteControlEvents

Tells the app to begin receiving remote-control events.

- endReceivingRemoteControlEvents

Tells the app to stop receiving remote-control events.

Controlling App Appearance

statusBarFrame

The frame rectangle defining the area of the status bar.

networkActivityIndicatorVisible

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

userInterfaceLayoutDirection

Returns the layout direction of the user interface.

UIUserInterfaceLayoutDirection

Specifies the directional flow of the user interface.

Controlling and Handling Events

- sendEvent:

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

- sendAction:to:from:forEvent:

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

- beginIgnoringInteractionEvents

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

- endIgnoringInteractionEvents

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

ignoringInteractionEvents

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

applicationSupportsShakeToEdit

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

Managing the App's Icon

applicationIconBadgeNumber

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

supportsAlternateIcons

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

alternateIconName

The name of the icon being displayed for the app.

Getting App Windows

keyWindow

The app's key window.

windows

The app's visible and hidden windows.

Getting the Font Sizing Preference

preferredContentSizeCategory

The font sizing option preferred by the user.

UIContentSizeCategory

Constants indicating the preferred size of your content.

Managing the Default Interface Orientations

- supportedInterfaceOrientationsForWindow:

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

Managing Status Bar Animations

statusBarOrientationAnimationDuration

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

Constants

UIStatusBarStyle

The style of the device’s status bar.

UIStatusBarAnimation

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

UserInfo Dictionary Keys

Keys used to access values in the userInfo dictionary of some UIApplication-posted notifications.

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.

Notifications

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

UIApplicationBackgroundRefreshStatusDidChangeNotification

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

UIApplicationDidBecomeActiveNotification

Posted when the app becomes active.

UIApplicationDidChangeStatusBarFrameNotification

Posted when the frame of the status bar changes.

UIApplicationDidChangeStatusBarOrientationNotification

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

UIApplicationDidEnterBackgroundNotification

Posted when the app enters the background.

UIApplicationDidFinishLaunchingNotification

Posted immediately after the app finishes launching.

UIApplicationDidReceiveMemoryWarningNotification

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

UIApplicationProtectedDataDidBecomeAvailable

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

UIApplicationProtectedDataWillBecomeUnavailable

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

UIApplicationSignificantTimeChangeNotification

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.

UIApplicationUserDidTakeScreenshotNotification

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

UIApplicationWillChangeStatusBarOrientationNotification

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

UIApplicationWillChangeStatusBarFrameNotification

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

UIApplicationWillEnterForegroundNotification

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

UIApplicationWillResignActiveNotification

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

UIApplicationWillTerminateNotification

Posted when the app is about to terminate.

UIContentSizeCategoryDidChangeNotification

Posted when the user changes the preferred content size setting.

Deprecated Symbols

- registerUserNotificationSettings:

Registers your preferred options for notifying the user.

Deprecated
currentUserNotificationSettings

Returns the user notification settings for the app.

Deprecated
UIRemoteNotificationType

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

Deprecated
- openURL:

Attempts to open the resource at the specified URL.

Deprecated
- scheduleLocalNotification:

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

Deprecated
- presentLocalNotificationNow:

Presents a local notification immediately.

Deprecated
- cancelLocalNotification:

Cancels the delivery of the specified scheduled local notification.

Deprecated
- cancelAllLocalNotifications

Cancels the delivery of all scheduled local notifications.

Deprecated
scheduledLocalNotifications

All currently scheduled local notifications.

Deprecated
- setNewsstandIconImage:

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

Deprecated
- setKeepAliveTimeout:handler:

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

Deprecated
- clearKeepAliveTimeout

Removes a previously installed periodic handler block.

Deprecated
- setStatusBarHidden:withAnimation:

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

Deprecated
statusBarHidden

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

Deprecated
- setStatusBarStyle:animated:

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

Deprecated
statusBarStyle

The current style of the status bar.

Deprecated
- setStatusBarOrientation:animated:

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

Deprecated
statusBarOrientation

The current orientation of the app's status bar.

Deprecated
- registerForRemoteNotificationTypes:

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

Deprecated
- enabledRemoteNotificationTypes

Returns the types of notifications the app accepts.

Deprecated
proximitySensingEnabled

A Boolean value that determines whether proximity sensing is enabled.

Deprecated
- setStatusBarHidden:animated:

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

Deprecated

Relationships

Inherits From

See Also

Application

Managing Your App's Life Cycle

Understand how the app delegate manages your app's high-level behavior.

UIApplicationDelegate

A set of methods that are called by the singleton UIApplication object in response to important events in the lifetime of your app.

Allowing Apps and Websites to Link to Your Content

Use universal links to link to content within your app and share data securely.

UIApplicationMain

Creates the application object and the application delegate and sets up the event cycle.