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 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:
Temporarily suspend incoming touch events (
beginIgnoringInteractionEvents)Register for remote notifications (
unregisterForRemoteNotifications)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 (
beginBackgroundTaskWithExpirationHandler:,beginBackgroundTaskWithName:expirationHandler:)Schedule and cancel local notifications (
scheduleLocalNotification:,cancelLocalNotification:)Coordinate the reception of remote-control events (
beginReceivingRemoteControlEvents,endReceivingRemoteControlEvents)Perform app-level state restoration tasks (methods in the Managing the State Restoration Behavior task group)
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.
-
Returns the singleton app instance.
Declaration
Swift
class func sharedApplication() -> UIApplicationObjective-C
+ (UIApplication *)sharedApplicationReturn Value
The app instance is created in the
UIApplicationMainfunction.Availability
Available in iOS 2.0 and later.
Not available in app extensions.
-
The delegate of the app object.
Declaration
Swift
unowned(unsafe) var delegate: UIApplicationDelegate?Objective-C
@property(nonatomic, assign) id< UIApplicationDelegate > delegateDiscussion
Every app must have an app delegate object to respond to app-related messages. For example, the app notifies its delegate when the app finishes launching and when its foreground or background execution status changes. Similarly, app-related messages coming from the system are often routed to the app delegate for handling. Xcode provides an initial app delegate for every app and you should not need to change this delegate later.
The delegate must adopt the
UIApplicationDelegateformal protocol.Availability
Available in iOS 2.0 and later.
-
The app's key window. (read-only)
Declaration
Swift
var keyWindow: UIWindow? { get }Objective-C
@property(nonatomic, readonly) UIWindow *keyWindowDiscussion
This property holds the
UIWindowobject in thewindowsarray that is most recently sent themakeKeyAndVisiblemessage.Availability
Available in iOS 2.0 and later.
See Also
-
The app's visible and hidden windows. (read-only)
Declaration
Swift
var windows: [UIWindow] { get }Objective-C
@property(nonatomic, readonly) NSArray <__kindof UIWindow *> *windowsDiscussion
This property contains the
UIWindowobjects currently associated with the app. This list does not include windows created and managed by the system, such as the window used to display the status bar.The windows in the array are ordered from back to front by window level; thus, the last window in the array is on top of all other app windows.
Availability
Available in iOS 2.0 and later.
See Also
-
Dispatches an event to the appropriate responder objects in the app.
Parameters
eventA
UIEventobject encapsulating the information about an event, including the touches involved.Discussion
If you require it, you can intercept incoming events by subclassing
UIApplicationand overriding this method. For every event you intercept, you must dispatch it by calling[super sendEvent:event]after handling the event in your implementation.Availability
Available in iOS 2.0 and later.
See Also
-
Sends an action message identified by selector to a specified target.
Declaration
Swift
func sendAction(_action: Selector, totarget: AnyObject?, fromsender: AnyObject?, forEventevent: UIEvent?) -> BoolObjective-C
- (BOOL)sendAction:(SEL)actionto:(id)targetfrom:(id)senderforEvent:(UIEvent *)eventParameters
actionA selector identifying an action method. See the discussion for information on the permitted selector forms.
targetThe object to receive the action message. If
targetisnil, the app sends the message to the first responder, from whence it progresses up the responder chain until it is handled.senderThe object that is sending the action message. The default sender is the
UIControlobject that invokes this method.eventA
UIEventobject that encapsulates information about the event originating the action message.Return Value
YEStrueif a responder object handled the action message,NOfalseif no object in the responder chain handled the message.Discussion
Normally, this method is invoked by a
UIControlobject that the user has touched. The default implementation dispatches the action method to the given target object or, if no target is specified, to the first responder. Subclasses may override this method to perform special dispatching of action messages.By default, this method pushes two parameters when calling the target. These last two parameters are optional for the receiver because it is up to the caller (usually a
UIControlobject) to remove any parameters it added. This design enables the action selector to be one of the following:- (void)action- (void)action:(id)sender- (void)action:(id)sender forEvent:(UIEvent *)event
Availability
Available in iOS 2.0 and later.
See Also
-
Tells the receiver to suspend the handling of touch-related events.
Declaration
Swift
func beginIgnoringInteractionEvents()Objective-C
- (void)beginIgnoringInteractionEventsDiscussion
You typically call this method before starting an animation or transition. Calls are nested with the
endIgnoringInteractionEventsmethod.Availability
Available in iOS 2.0 and later.
Not available in app extensions.
See Also
-
Tells the receiver to resume the handling of touch-related events.
Declaration
Swift
func endIgnoringInteractionEvents()Objective-C
- (void)endIgnoringInteractionEventsDiscussion
You typically call this method when, after calling the
beginIgnoringInteractionEventsmethod, the animation or transition concludes. Nested calls of this method should match nested calls of thebeginIgnoringInteractionEventsmethod.Availability
Available in iOS 2.0 and later.
Not available in app extensions.
See Also
-
Returns whether the receiver is ignoring events initiated by touches on the screen.
Declaration
Swift
func isIgnoringInteractionEvents() -> BoolObjective-C
- (BOOL)isIgnoringInteractionEventsReturn Value
YEStrueif the receiver is ignoring interaction events; otherwiseNOfalse. The method returnsYEStrueif the nestedbeginIgnoringInteractionEventsandendIgnoringInteractionEventscalls are at least one level deep.Availability
Available in iOS 2.0 and later.
-
A Boolean value that determines whether shaking the device displays the undo-redo user interface.
Declaration
Swift
var applicationSupportsShakeToEdit: BoolObjective-C
@property(nonatomic) BOOL applicationSupportsShakeToEditDiscussion
The default value is
YEStrue. Set the property toNOfalseif you don’t want your app to display the Undo and Redo buttons when users shake the device.Availability
Available in iOS 3.0 and later.
-
Attempts to open the resource at the specified URL.
Parameters
urlA URL (Universal Resource Locator). UIKit supports many common schemes, including the
http,https,tel,facetime, andmailtoschemes. You can also employ custom URL schemes associated with apps installed on the device.Return Value
YEStrueif the resource located by the URL was successfully opened; otherwiseNOfalse.Discussion
The URL you pass to this method can identify a resource in the app that calls the method, or a resource to be handled by another app. If the resource is to be handled another app, invoking this method might cause the calling app to quit so the other can launch.
To check if there is an installed app that can handle a scheme, call the
canOpenURL:method before calling this one. Be sure to read the description of that method for an important note about registering the schemes you want to employ.Availability
Available in iOS 2.0 and later.
Not available in app extensions.
See Also
application:handleOpenURL:(UIApplicationDelegate)– canOpenURL: -
Returns a Boolean value indicating whether or not the URL’s scheme can be handled by some app installed on the device.
Parameters
urlA URL (Universal Resource Locator). At runtime, the system tests the URL’s scheme to determine if there is an installed app that is registered to handle the scheme. More than one app can be registered to handle a scheme.
The URL you pass to this method can have a common scheme or a custom scheme.
Return Value
NOfalseif there is no app installed on the device that is registered to handle the URL’s scheme, or if you have not declared the URL’s scheme in yourInfo.plistfile; otherwise,YEStrue.Read the Discussion section for more information on conditions that affect the return value.
Discussion
If this method returns
YEStruefor a given URL, iOS guarantees that that if theopenURL:method is subsequently called using the same URL, an app registered to handle the URL’s scheme will launch to handle it. This method’s return value does not indicate whether or not the full URL is valid or if the specified resource exists.If your app is linked against an earlier version of iOS but is running in iOS 9.0 or later, you can call this method on 50 distinct URL schemes. After hitting this limit, subsequent calls to this method return
NOfalse. If a user reinstalls or upgrades the app, iOS resets the limit.Unlike this method, the
openURL:method is not constrained by the LSApplicationQueriesSchemes requirement: If an app that handles a scheme is installed on the device, theopenURL:method works, whether or not you have declared the scheme.Availability
Available in iOS 3.0 and later.
See Also
-
Registers your preferred options for notifying the user.
Declaration
Swift
func registerUserNotificationSettings(_notificationSettings: UIUserNotificationSettings)Objective-C
- (void)registerUserNotificationSettings:(UIUserNotificationSettings *)notificationSettingsParameters
notificationSettingsThe types of notifications that your app wants to use. You also use this object to specify custom actions that can be initiated by the user from an alert displayed in response to a local or remote notification.
Discussion
If your app displays alerts, play sounds, or badges its icon, you must call this method during your launch cycle to request permission to alert the user in these ways. (You must also make this request if you want to set the
applicationIconBadgeNumberproperty directly.) Typically, you make this request if your app uses local or remote notifications to alert the user to new information involving your app. The first time your app launches and calls this method, the system asks the user whether your app should be allowed to deliver notifications and stores the response. Thereafter, the system uses the stored response to determine the actual types of notifications you may use.After calling this method, the app calls the
application:didRegisterUserNotificationSettings:method of its app delegate to report the results. You can use that method to determine if your request was granted or denied by the user.It is recommended that you call this method before you schedule any local notifications or register with the push notification service. Calling this method with a new user settings object replaces the previous settings request. Apps that support custom actions must include all of their supported actions in the
notificationSettingsobject.Availability
Available in iOS 8.0 and later.
See Also
-
Returns the user notification settings for the app.
Declaration
Swift
func currentUserNotificationSettings() -> UIUserNotificationSettings?Objective-C
- (UIUserNotificationSettings *)currentUserNotificationSettingsReturn Value
A user notification settings object indicating the types of notifications that your app may use.
Discussion
If you configure local or remote notifications with unavailable notification types, the system does not display the corresponding alerts to the user. The system does still deliver the local and remote notifications to your app.
Availability
Available in iOS 8.0 and later.
See Also
-
Register to receive remote notifications via Apple Push Notification service.
Declaration
Swift
func registerForRemoteNotifications()Objective-C
- (void)registerForRemoteNotificationsDiscussion
Call this method to initiate the registration process with Apple Push Notification service. If registration succeeds, the app calls your app delegate object’s
application:didRegisterForRemoteNotificationsWithDeviceToken:method and passes it a device token. You should pass this token along to the server you use to generate remote notifications for the device. If registration fails, the app calls its app delegate’sapplication:didFailToRegisterForRemoteNotificationsWithError:method instead.If you want your app’s remote notifications to display alerts, play sounds, or perform other user-facing actions, you must call the
registerUserNotificationSettings:method to request the types of notifications you want to use. If you do not call that method, the system delivers all remote notifications to your app silently. Because the registration process takes into account the user’s preferred notification settings, requesting access to user-facing notification types also does not guarantee that they will be granted. To find out what notification settings are available, use thecurrentUserNotificationSettingsmethod.Availability
Available in iOS 8.0 and later.
See Also
-
Unregister for all remote notifications received via Apple Push Notification service.
Declaration
Swift
func unregisterForRemoteNotifications()Objective-C
- (void)unregisterForRemoteNotificationsDiscussion
You should call this method in rare circumstances only, such as when a new version of the app removes support for all types of remote notifications. Users can temporarily prevent apps from receiving remote notifications through the Notifications section of the Settings app. Apps unregistered through this method can always re-register.
Availability
Available in iOS 3.0 and later.
See Also
-
Returns a Boolean indicating whether the app is currently registered for remote notifications.
Declaration
Swift
func isRegisteredForRemoteNotifications() -> BoolObjective-C
- (BOOL)isRegisteredForRemoteNotificationsReturn Value
YEStrueif the app is registered for remote notifications and received its device token orNOfalseif registration has not occurred, has failed, or has been denied by the user.Discussion
This method reflects only the successful completion of the remote registration process that begins when you call the
registerForRemoteNotificationsmethod. This method does not reflect whether remote notifications are actually available due to connectivity issues. The value returned by this method takes into account the user’s preferences for receiving remote notifications.Availability
Available in iOS 8.0 and later.
-
Schedules a local notification for delivery at its encapsulated date and time.
Declaration
Swift
func scheduleLocalNotification(_notification: UILocalNotification)Objective-C
- (void)scheduleLocalNotification:(UILocalNotification *)notificationParameters
notificationThe local notification object that you want to schedule. This object contains information about when to deliver the notification and what to do when that date occurs. The system keeps a copy of this object so you may release the object once it is scheduled.
Discussion
Prior to scheduling any local notifications, you must call the
registerUserNotificationSettings:method to let the system know what types of alerts, if any, you plan to display to the user.Availability
Available in iOS 4.0 and later.
-
Presents a local notification immediately.
Declaration
Swift
func presentLocalNotificationNow(_notification: UILocalNotification)Objective-C
- (void)presentLocalNotificationNow:(UILocalNotification *)notificationParameters
notificationA local notification that the operating system presents for the app immediately, regardless of the value of the notification’s
fireDateproperty. Apps running in the background state can immediately present local notifications when there are incoming chats, messages, or updates. Because the operating system copiesnotification, you may release it once you have scheduled it.Discussion
Prior to scheduling any local notifications, you must call the
registerUserNotificationSettings:method to let the system know what types of alerts, if any, you plan to display to the user.Availability
Available in iOS 4.0 and later.
-
Cancels the delivery of the specified scheduled local notification.
Declaration
Swift
func cancelLocalNotification(_notification: UILocalNotification)Objective-C
- (void)cancelLocalNotification:(UILocalNotification *)notificationParameters
notificationThe local notification to cancel.
Discussion
Calling this method also programmatically dismisses the notification if it is currently displaying an alert.
Availability
Available in iOS 4.0 and later.
See Also
-
Cancels the delivery of all scheduled local notifications.
Declaration
Swift
func cancelAllLocalNotifications()Objective-C
- (void)cancelAllLocalNotificationsAvailability
Available in iOS 4.0 and later.
See Also
-
All currently scheduled local notifications.
Declaration
Swift
var scheduledLocalNotifications: [UILocalNotification]?Objective-C
@property(nonatomic, copy) NSArray <UILocalNotification *> *scheduledLocalNotificationsDiscussion
This property holds an array of
UILocalNotificationobjects representing the current scheduled local notifications. Use this property to access the currently scheduled notifications, perhaps to cancel them. Assigning a new value to this property implicitly schedules all of the notifications in the new array.This method may be faster than using
scheduleLocalNotification:when scheduling a large number of notifications.Availability
Available in iOS 4.0 and later.
-
applicationState applicationStatePropertyThe runtime state of the app. (read-only)
Declaration
Swift
var applicationState: UIApplicationState { get }Objective-C
@property(nonatomic, readonly) UIApplicationState applicationStateDiscussion
An app may be active, inactive, or running in the background. You can use the value in this property to determine which of these states the app is currently in.
Availability
Available in iOS 4.0 and later.
-
The amount of time the app has to run in the background. (read-only)
Declaration
Swift
var backgroundTimeRemaining: NSTimeInterval { get }Objective-C
@property(nonatomic, readonly) NSTimeInterval backgroundTimeRemainingDiscussion
This property contains the amount of time the app has to run in the background before it may be forcibly killed by the system. While the app is running in the foreground, the value in this property remains suitably large. If the app starts one or more long-running tasks using the
beginBackgroundTaskWithExpirationHandler:method and then transitions to the background, the value of this property is adjusted to reflect the amount of time the app has left to run.Availability
Available in iOS 4.0 and later.
-
The ability of the app to be launched into the background so that it can perform background behaviors. (read-only)
Declaration
Swift
var backgroundRefreshStatus: UIBackgroundRefreshStatus { get }Objective-C
@property(nonatomic, readonly) UIBackgroundRefreshStatus backgroundRefreshStatusDiscussion
This property reflects whether the app can be launched into the background to handle background behaviors, such as processing background location updates and performing background fetches. If your app relies on being launched into the background to perform tasks, you can use the value of this property to determine if doing so is possible and to warn the user if it is not. Do not warn the user if the value of this property is set to
UIBackgroundRefreshStatusRestricted; a restricted user does not have the ability to enable multitasking for the app.Availability
Available in iOS 7.0 and later.
-
Specifies the minimum amount of time that must elapse between background fetch operations.
Declaration
Swift
func setMinimumBackgroundFetchInterval(_minimumBackgroundFetchInterval: NSTimeInterval)Objective-C
- (void)setMinimumBackgroundFetchInterval:(NSTimeInterval)minimumBackgroundFetchIntervalParameters
minimumBackgroundFetchIntervalThe minimum number of seconds that must elapse before another background fetch can be initiated. This value is advisory only and does not indicate the exact amount of time expected between fetch operations.
Discussion
This property has no effect for apps that do not have the
UIBackgroundModeskey with thefetchvalue in itsInfo.plistfile.The default fetch interval for apps is
UIApplicationBackgroundFetchIntervalNever. Therefore, you must call this method and set a fetch interval before your app is given background execution time.Availability
Available in iOS 7.0 and later.
-
Marks the beginning of a new long-running background task with the specified name.
Declaration
Swift
func beginBackgroundTaskWithName(_taskName: String?, expirationHandlerhandler: (() -> Void)?) -> UIBackgroundTaskIdentifierObjective-C
- (UIBackgroundTaskIdentifier)beginBackgroundTaskWithName:(NSString *)taskNameexpirationHandler:(void (^)(void))handlerParameters
taskNameThe name to display in the debugger when viewing the background task. If you specify
nilfor this parameter, this method generates a name based on the name of the calling function or method.handlerA handler to be called shortly before the app’s remaining background time reaches 0. You should use this handler to clean up and mark the end of the background task. Failure to end the task explicitly will result in the termination of the app. The handler is called synchronously on the main thread, blocking the app’s suspension momentarily while the app is notified.
Return Value
A unique identifier for the new background task. You must pass this value to the
endBackgroundTask:method to mark the end of this task. This method returnsUIBackgroundTaskInvalidif running in the background is not possible.Discussion
The behavior of this method is identical to the behavior of the
beginBackgroundTaskWithExpirationHandler:method except for the addition of an explicit name for the task.Availability
Available in iOS 7.0 and later.
-
Marks the beginning of a new long-running background task.
Declaration
Swift
func beginBackgroundTaskWithExpirationHandler(_handler: (() -> Void)?) -> UIBackgroundTaskIdentifierObjective-C
- (UIBackgroundTaskIdentifier)beginBackgroundTaskWithExpirationHandler:(void (^)(void))handlerParameters
handlerA handler to be called shortly before the app’s remaining background time reaches 0. You should use this handler to clean up and mark the end of the background task. Failure to end the task explicitly will result in the termination of the app. The handler is called synchronously on the main thread, blocking the app’s suspension momentarily while the app is notified.
Return Value
A unique identifier for the new background task. You must pass this value to the
endBackgroundTask:method to mark the end of this task. This method returnsUIBackgroundTaskInvalidif running in the background is not possible.Discussion
This method lets your app continue to run for a period of time after it transitions to the background. You should call this method at times where leaving a task unfinished might be detrimental to your app’s user experience. For example, your app could call this method to ensure that had enough time to transfer an important file to a remote server or at least attempt to make the transfer and note any errors. You should not use this method simply to keep your app running after it moves to the background.
Each call to this method must be balanced by a matching call to the
endBackgroundTask:method. Apps running background tasks have a finite amount of time in which to run them. (You can find out how much time is available using thebackgroundTimeRemainingproperty.) If you do not callendBackgroundTask:for each task before time expires, the system kills the app. If you provide a block object in thehandlerparameter, the system calls your handler before time expires to give you a chance to end the task.You can call this method at any point in your app’s execution. You may also call this method multiple times to mark the beginning of several background tasks that run in parallel. However, each task must be ended separately. You identify a given task using the value returned by this method.
To assist with debugging, this method generates a name for the task that is based on the name of the calling method or function. If you want to specify a custom name, use the
beginBackgroundTaskWithName:expirationHandler:method instead.This method can be safely called on a non-main thread.
Availability
Available in iOS 4.0 and later.
See Also
-
Marks the end of a specific long-running background task.
Declaration
Swift
func endBackgroundTask(_identifier: UIBackgroundTaskIdentifier)Objective-C
- (void)endBackgroundTask:(UIBackgroundTaskIdentifier)identifierParameters
identifierAn identifier returned by the
beginBackgroundTaskWithExpirationHandler:method.Discussion
You must call this method to end a task that was started using the
beginBackgroundTaskWithExpirationHandler:method. If you do not, the system may kill your app.This method can be safely called on a non-main thread.
Availability
Available in iOS 4.0 and later.
-
idleTimerDisabled idleTimerDisabledPropertyA Boolean value that controls whether the idle timer is disabled for the app.
Declaration
Swift
var idleTimerDisabled: BoolObjective-C
@property(nonatomic, getter=isIdleTimerDisabled) BOOL idleTimerDisabledDiscussion
The default value of this property is
NOfalse. When most apps have no touches as user input for a short period, the system puts the device into a "sleep” state where the screen dims. This is done for the purposes of conserving power. However, apps that don't have user input except for the accelerometer—games, for instance—can, by setting this property toYEStrue, disable the “idle timer” to avert system sleep.Availability
Available in iOS 2.0 and later.
-
Tells the app that your code is restoring state asynchronously.
Declaration
Swift
func extendStateRestoration()Objective-C
- (void)extendStateRestorationDiscussion
UIKit restores your app’s state synchronously on the main thread. If you choose to perform additional state restoration on a secondary thread, call this method to inform UIKit of that fact. You must balance each call to this method with a matching call to the
completeStateRestorationmethod.Calling this method is a safety precaution in the event that your app crashes at launch time due to problems restoring its state. If you call this method but do not call the matching
completeStateRestorationmethod before a crash occurs, the system throws away any saved state information. Doing so prevents your app from crashing during subsequent launches because of issues caused by trying to restore your app’s state.Availability
Available in iOS 6.0 and later.
See Also
-
Tells the app that your code has finished any asynchronous state restoration.
Declaration
Swift
func completeStateRestoration()Objective-C
- (void)completeStateRestorationDiscussion
UIKit restores your app’s state synchronously on the main thread. If you choose to perform additional state restoration on a secondary thread, call the
extendStateRestorationmethod to inform UIKit of that fact. Call this method after you finish with your background work to let the system know that state restoration is complete.Availability
Available in iOS 6.0 and later.
See Also
-
Prevents the app from using the recent snapshot image during the next launch cycle.
Declaration
Swift
func ignoreSnapshotOnNextApplicationLaunch()Objective-C
- (void)ignoreSnapshotOnNextApplicationLaunchDiscussion
As part of the state preservation process, UIKit captures your app’s user interface and stores it in an image file. When your app is relaunched, the system displays this snapshot image in place of your app’s default launch image to preserve the notion that your app was still running. If you feel that the snapshot cannot correctly reflect your app’s user interface when your app is relaunched, call this method to let UIKit know that it should use your app’s default launch image instead of the snapshot.
You must call this method from within the code you use to preserve your app’s state.
Availability
Available in iOS 7.0 and later.
-
registerObjectForStateRestoration(_:restorationIdentifier:) + registerObjectForStateRestoration:restorationIdentifier:Registers a custom object for use with the state restoration system.
Declaration
Swift
class func registerObjectForStateRestoration(_object: UIStateRestoring, restorationIdentifierrestorationIdentifier: String)Objective-C
+ (void)registerObjectForStateRestoration:(id<UIStateRestoring>)objectrestorationIdentifier:(NSString *)restorationIdentifierParameters
objectThe object to be registered with the restoration archive. The object must adopt the
UIStateRestoringprotocol. This parameter must not benil.restorationIdentifierThe restoration identifier for the object. UIKit uses this parameter to distinguish the object from other objects in the archive. This parameter must not be
nil.Discussion
You use this method to register objects that you want to save as part of the overall state restoration process. Registering the object makes it available for inclusion in the restoration archive but does not automatically include it. To include the object, refer to it from one of your other interface objects. For example, you might write out a reference to the object from the
encodeRestorableStateWithCoder:method of one of your view controllers.Availability
Available in iOS 7.0 and later.
-
shortcutItems shortcutItemsPropertyThe Home screen dynamic quick actions for your app; available on devices that support 3D Touch.
Declaration
Swift
var shortcutItems: [UIApplicationShortcutItem]?Objective-C
@property(nonatomic, copy) NSArray <UIApplicationShortcutItem *> *shortcutItemsDiscussion
Set this property to register an array of dynamic quick actions to display on the Home screen when a user presses your app icon. Read this property to retrieve the currently registered Home screen dynamic quick actions.
The items in the
shortcutItemsarray are instances of theUIApplicationShortcutItemclass, and are therefore immutable.The system populates the displayed set of Home screen quick actions, starting at the top, first with your static quick actions. Only if there are additional positions available does it also show your dynamic quick actions, up to the system-defined limit.
The onscreen ordering of your Home screen quick actions reflects the ordering in your UIApplicationShortcutItems array (if that array contains items) and the ordering of the items in the
shortcutItemsarray (if any are displayed).Availability
Available in iOS 9.0 and later.
-
A Boolean value indicating whether content protection is active. (read-only)
Declaration
Swift
var protectedDataAvailable: Bool { get }Objective-C
@property(nonatomic, readonly, getter=isProtectedDataAvailable) BOOL protectedDataAvailableDiscussion
The value of this property is
NOfalseif data protection is enabled and the device is currently locked. The value of this property is set toYEStrueif the device is unlocked or if content protection is not enabled.When the value of this property is
NOfalse, files that were assigned theNSFileProtectionCompleteorNSFileProtectionCompleteUnlessOpenprotection key cannot be read or written by your app. The user must unlock the device before your app can access them.Availability
Available in iOS 4.0 and later.
-
Tells the app to begin receiving remote-control events.
Declaration
Swift
func beginReceivingRemoteControlEvents()Objective-C
- (void)beginReceivingRemoteControlEventsDiscussion
In iOS 7.1 and later, use the shared
MPRemoteCommandCenterobject to register for remote control events. You do not need to call this method when using the shared command center object.This method starts the delivery of remote control events using the responder chain. Remote-control events originate as commands issued by headsets and external accessories that are intended to control multimedia presented by an app. To stop the reception of remote-control events, you must call
endReceivingRemoteControlEvents.Availability
Available in iOS 4.0 and later.
-
Tells the app to stop receiving remote-control events.
Declaration
Swift
func endReceivingRemoteControlEvents()Objective-C
- (void)endReceivingRemoteControlEventsDiscussion
In iOS 7.1 and later, use the shared
MPRemoteCommandCenterobject to unregister for remote control events. You do not need to call this method when using the shared command center object.This method stops the delivery of remote control events using the responder chain. Remote-control events originate as commands issued by headsets and external accessories that are intended to control multimedia presented by an app.
Availability
Available in iOS 4.0 and later.
See Also
-
statusBarFrame statusBarFramePropertyThe frame rectangle defining the area of the status bar. (read-only)
Declaration
Swift
var statusBarFrame: CGRect { get }Objective-C
@property(nonatomic, readonly) CGRect statusBarFrameDiscussion
The value of this property is
CGRectZeroif the status bar is hidden.Availability
Available in iOS 2.0 and later.
See Also
-
A Boolean value that turns an indicator of network activity on or off.
Declaration
Swift
var networkActivityIndicatorVisible: BoolObjective-C
@property(nonatomic, getter=isNetworkActivityIndicatorVisible) BOOL networkActivityIndicatorVisibleDiscussion
Specify
YEStrueif the app should show network activity andNOfalseif it should not. The default value isNOfalse. A spinning indicator in the status bar shows network activity. The app may explicitly hide or show this indicator.Availability
Available in iOS 2.0 and later.
-
The number currently set as the badge of the app icon in Springboard.
Declaration
Swift
var applicationIconBadgeNumber: IntObjective-C
@property(nonatomic) NSInteger applicationIconBadgeNumberDiscussion
Set to 0 (zero) to hide the badge number. The default value of this property is 0.
Availability
Available in iOS 2.0 and later.
-
Returns the layout direction of the user interface. (read-only)
Declaration
Swift
var userInterfaceLayoutDirection: UIUserInterfaceLayoutDirection { get }Objective-C
@property(nonatomic, readonly) UIUserInterfaceLayoutDirection userInterfaceLayoutDirectionDiscussion
This method specifies the general user interface layout flow direction. See UIUserInterfaceLayoutDirection for a description of the constants returned by this property.
Availability
Available in iOS 5.0 and later.
-
The font sizing option preferred by the user. (read-only)
Declaration
Swift
var preferredContentSizeCategory: String { get }Objective-C
@property(nonatomic, readonly) NSString *preferredContentSizeCategoryDiscussion
Users can request that apps display fonts in a size that is larger or smaller than the normal font size defined by the system. For example, a user with a visual impairment might request a larger default font size to make it easier to read text. Font objects returned by the system automatically scale based on the user’s preference. You can use the value of this property to request a font object of the appropriate size.
When the value of this property changes, the app object sends a
UIContentSizeCategoryDidChangeNotificationnotification so that observers can respond accordingly.For a list of possible values, see Content Size Category Constants and Accessibility Content Size Category Constants.
Availability
Available in iOS 7.0 and later.
-
Returns the default set of interface orientations to use for the view controllers in the specified window.
Declaration
Swift
func supportedInterfaceOrientationsForWindow(_window: UIWindow?) -> UIInterfaceOrientationMaskObjective-C
- (UIInterfaceOrientationMask)supportedInterfaceOrientationsForWindow:(UIWindow *)windowParameters
windowThe window whose default interface orientations you want to retrieve.
Return Value
A bit mask specifying which orientations are supported. See
UIInterfaceOrientationMaskfor valid bit-mask values. The value returned by this method must not be0.Discussion
Starting in iOS 8, you should employ the
UITraitCollectionandUITraitEnvironmentAPIs, and size class properties as used in those APIs, instead of using this method or otherwise writing your app in terms of interface orientation.This method returns the default interface orientations for the app. These orientations are used only for view controllers that do not specify their own. If your app delegate implements the
application:supportedInterfaceOrientationsForWindow:method, the system does not call this method.The default implementation of this method returns the app’s default set of supported interface orientations, as you define them in the UISupportedInterfaceOrientations key of the
Info.plistfile in your Xcode project. If the file does not contain that key, this method returns all interface orientations for the iPad idiom and returns all interface orientations except the portrait upside-down orientation for the iPhone idiom.Availability
Available in iOS 6.0 and later.
-
The animation duration in seconds for the status bar during a 90 degree orientation change. (read-only)
Declaration
Swift
var statusBarOrientationAnimationDuration: NSTimeInterval { get }Objective-C
@property(nonatomic, readonly) NSTimeInterval statusBarOrientationAnimationDurationDiscussion
You should double the value of this property for a 180 degree orientation change in the status bar.
Availability
Available in iOS 2.0 and later.
See Also
-
Sets the icon of a Newsstand app to an image depicting the current issue of a publication.
Declaration
Swift
func setNewsstandIconImage(_image: UIImage?)Objective-C
- (void)setNewsstandIconImage:(UIImage *)imageParameters
imageAn image to use as the icon of a Newsstand app. Pass
nilto clear the currently set image and revert to the icon stored in the app bundle.Discussion
The Newsstand app icon is typically downloaded from the app’s server for each issue.
Availability
Available in iOS 9.0 and later.
Deprecated in iOS 9.0.
-
Configures a periodic handler for VoIP apps in older versions of iOS.
Declaration
Swift
func setKeepAliveTimeout(_timeout: NSTimeInterval, handlerkeepAliveHandler: (() -> Void)?) -> BoolObjective-C
- (BOOL)setKeepAliveTimeout:(NSTimeInterval)timeouthandler:(void (^)(void))keepAliveHandlerParameters
timeoutThe maximum interval (measured in seconds) at which your app should be woken up to check its VoIP connection. The minimum acceptable timeout value is 600 seconds.
keepAliveHandlerA block that performs the tasks needed to maintain your VoIP network connection. Setting this parameter to
nilreleases the current handler block and prevents UIKit from scheduling the next wake.Return Value
YEStrueif the handler was installed orNOfalseif it was not.Discussion
In iOS 8 and later, voice-over-IP (VoIP) apps register for
registerForRemoteNotificationsremote notifications instead of using this method. Using remote notifications eliminates the need for a timeout handler to check in with the VoIP service. Instead, when a calls arrives for the user, the VoIP service sends a VoIP remote notification to the user’s device. Upon receiving this notification, the device launches or wakes the app as needed so that it can handle the incoming call.In iOS 7 and earlier, VoIP apps use this method to install a handler whose job is to maintain the app’s network connection with a VoIP server. This handler is guaranteed to be called before the specified timeout value but may be called at a slightly different time interval in order to better align execution of your handler with other system tasks, and thereby save power. Your handler has a maximum of 10 seconds to perform any needed tasks and exit. If it does not exit before time expires, the app is suspended.
Timeout values and handlers are not persisted between app launches. Therefore, if your app is terminated for any reason, you must reinstall the handler during the next launch cycle.
For calls to this method to succeed, the app must have the
voipvalue in the array associated with theUIBackgroundModeskey in itsInfo.plistfile. Calling this method replaces the previously installed handler and timeout values, if any.Availability
Available in iOS 4.0 and later.
Deprecated in iOS 9.0.
-
Removes a previously installed periodic handler block.
Declaration
Swift
func clearKeepAliveTimeout()Objective-C
- (void)clearKeepAliveTimeoutDiscussion
If your VoIP app no longer needs to be woken up at periodic intervals, you can use this method to remove any previously installed handler.
Availability
Available in iOS 4.0 and later.
Deprecated in iOS 9.0.
-
Hides or shows the status bar, optionally animating the transition.
Declaration
Swift
func setStatusBarHidden(_hidden: Bool, withAnimationanimation: UIStatusBarAnimation)Objective-C
- (void)setStatusBarHidden:(BOOL)hiddenwithAnimation:(UIStatusBarAnimation)animationParameters
hiddenYEStrueto hide the status bar,NOfalseto show the status bar.animationA constant that indicates whether there should be an animation and, if one is requested, whether it should fade the status bar in or out or whether it should slide the status bar in or out.
Discussion
See the descriptions of the constants of the
UIStatusBarAnimationtype for more information.Availability
Available in iOS 3.2 and later.
Deprecated in iOS 9.0.
-
A Boolean value that determines whether the status bar is hidden.
Declaration
Swift
var statusBarHidden: BoolObjective-C
@property(readonly, nonatomic, getter=isStatusBarHidden) BOOL statusBarHiddenReturn Value
YEStruemeans the status bar is hidden;NOfalsemeans it's visible.Discussion
Changing the value of this property changes the visibility of the status bar immediately—that is, without animations.
Availability
Available in iOS 2.0 and later.
Deprecated in iOS 9.0.
See Also
-
Sets the style of the status bar, optionally animating the transition to the new style.
Declaration
Swift
func setStatusBarStyle(_statusBarStyle: UIStatusBarStyle, animatedanimated: Bool)Objective-C
- (void)setStatusBarStyle:(UIStatusBarStyle)statusBarStyleanimated:(BOOL)animatedParameters
statusBarStyleA constant that specifies a style for the status bar. See the descriptions of the constants in UIStatusBarStyle for details.
animatedYEStrueif the transition to the new style should be animated; otherwiseNOfalse.Discussion
The animation slides the status bar out toward the top of the interface.
In iOS 7 and later, status bar behavior is determined by view controllers, and so calling this method has no effect by default. When view controller-based status bar appearance is disabled, this method behaves normally. To opt out of the view controller-based status bar appearance behavior, you must add the
UIViewControllerBasedStatusBarAppearancekey with a value ofNOfalseto your app’sInfo.plistfile, but doing so is not recommended.Availability
Available in iOS 2.0 and later.
Deprecated in iOS 9.0.
See Also
-
The current style of the status bar.
Declaration
Swift
var statusBarStyle: UIStatusBarStyleObjective-C
@property(readonly, nonatomic) UIStatusBarStyle statusBarStyleDiscussion
The value of the property is a UIStatusBarStyle constant that indicates the style of status. The default style is
UIStatusBarStyleDefault. Changing this property sets the new style immediately without animations.Availability
Available in iOS 2.0 and later.
Deprecated in iOS 9.0.
See Also
-
Sets the app's status bar to the specified orientation, optionally animating the transition.
Declaration
Swift
func setStatusBarOrientation(_interfaceOrientation: UIInterfaceOrientation, animatedanimated: Bool)Objective-C
- (void)setStatusBarOrientation:(UIInterfaceOrientation)interfaceOrientationanimated:(BOOL)animatedParameters
interfaceOrientationA specific orientation of the status bar. See UIInterfaceOrientation for details. The default value is
UIInterfaceOrientationPortrait.animatedYEStrueif the transition to the new orientation should be animated;NOfalseif it should be immediate, without animation.Discussion
Calling this method changes the value of the
statusBarOrientationproperty and rotates the status bar, animating the transition if animated isYEStrue. If your app has rotatable window content, however, you should not arbitrarily set status-bar orientation using this method. The status-bar orientation set by this method does not change if the device changes orientation.Availability
Available in iOS 2.0 and later.
Deprecated in iOS 9.0.
-
The current orientation of the app's status bar.
Declaration
Swift
var statusBarOrientation: UIInterfaceOrientationObjective-C
@property(readonly, nonatomic) UIInterfaceOrientation statusBarOrientationDiscussion
The value of this property is a constant that indicates an orientation of the receiver's status bar. See UIInterfaceOrientation for details. Setting this property rotates the status bar to the specified orientation without animating the transition. If your app has rotatable window content, however, you should not arbitrarily set status-bar orientation using this method. The status-bar orientation set by this method does not change if the device changes orientation. For more on rotatable window views, see View Controller Programming Guide for iOS.
Availability
Available in iOS 2.0 and later.
Deprecated in iOS 9.0.
See Also
-
Register to receive remote notifications of the specified types via Apple Push Notification service.
Deprecation Statement
Use the
registerForRemoteNotificationsmethod instead.Declaration
Swift
func registerForRemoteNotificationTypes(_types: UIRemoteNotificationType)Objective-C
- (void)registerForRemoteNotificationTypes:(UIRemoteNotificationType)typesParameters
typesA bit mask specifying the types of notifications the app accepts. For a list of values, see
UIRemoteNotificationType.Discussion
When you send this message, the device initiates the registration process with Apple Push Notification service. If it succeeds, the app delegate receives a device token in the
application:didRegisterForRemoteNotificationsWithDeviceToken:method; if registration doesn’t succeed, the delegate is informed via theapplication:didFailToRegisterForRemoteNotificationsWithError:method. If the app delegate receives a device token, it should connect with its provider and pass it the token.iOS does not display or play notification types specified in the notification payload that are not one of the requested ones. For example, if alert messages are not one of the accepted notification types, iOS does not display an alert even if one is specified in the notification payload. To find out what the app’s current notification types are, call the
enabledRemoteNotificationTypesmethod.Availability
Available in iOS 3.0 and later.
Deprecated in iOS 8.0.
-
Returns the types of notifications the app accepts.
Deprecation Statement
Use the
isRegisteredForRemoteNotificationsmethod instead.Declaration
Swift
func enabledRemoteNotificationTypes() -> UIRemoteNotificationTypeObjective-C
- (UIRemoteNotificationType)enabledRemoteNotificationTypesReturn Value
A bit mask whose values indicate the types of notifications the user has requested for the app. See
UIRemoteNotificationTypefor valid bit-mask values.Discussion
The values in the returned bit mask indicate the types of notifications currently enabled for the app. These types are first set when the app calls the
registerForRemoteNotificationTypes:method to register itself with Apple Push Notification service. Thereafter, the user may modify these accepted notification types in the Notifications preference of the Settings app. This method returns those initial or modified values. iOS does not display or play notification types specified in the notification payload that are not one of the enabled types. For example, the app might accept icon-badging as a form of notification, but might reject sounds and alert messages, even if they are specified in the notification payload.Availability
Available in iOS 3.0 and later.
Deprecated in iOS 8.0.
-
A Boolean value that determines whether proximity sensing is enabled.
Deprecation Statement
Use the
proximityMonitoringEnabledandproximityStateproperties of theUIDeviceclass instead.Declaration
Objective-C
@property(nonatomic, getter=isProximitySensingEnabled) BOOL proximitySensingEnabledDiscussion
YEStrueif proximity sensing is enabled; otherwiseNOfalse. Enabling proximity sensing tells iOS that it may need to blank the screen if the user's face is near it. Proximity sensing is disabled by default.Availability
Available in iOS 2.0 and later.
Deprecated in iOS 3.0.
-
- setStatusBarHidden:animated:(iOS 3.2)Hides or shows the status bar, optionally animating the transition.
Deprecation Statement
Use the
setStatusBarHidden:withAnimation:method instead.Declaration
Objective-C
- (void)setStatusBarHidden:(BOOL)hiddenanimated:(BOOL)animatedParameters
hiddenYEStrueif the status bar should be hidden,NOfalseif it should be visible. The default value isNOfalse.animatedYEStrueif the transition to or from a hidden state should be animated,NOfalseotherwise.Discussion
The animation fades the status bar out or in at the top of the interface, depending on the value of
hidden.Availability
Available in iOS 2.0 and later.
Deprecated in iOS 3.2.
See Also
Data Types
-
A unique token that identifies a request to run in the background.
Declaration
Swift
typealias UIBackgroundTaskIdentifier = IntObjective-C
typedef NSUInteger UIBackgroundTaskIdentifier;Import Statement
Objective-C
@import UIKit;Swift
import UIKitAvailability
Available in iOS 4.0 and later.
-
Constants indicating the types of notifications the app may display to the user.
Register for user notification settings using the
registerUserNotificationSettings:method instead.Declaration
Swift
struct UIRemoteNotificationType : OptionSetType { init(rawValuerawValue: UInt) static var None: UIRemoteNotificationType { get } static var Badge: UIRemoteNotificationType { get } static var Sound: UIRemoteNotificationType { get } static var Alert: UIRemoteNotificationType { get } static var NewsstandContentAvailability: UIRemoteNotificationType { get } }Objective-C
typedef enum : NSUInteger { UIRemoteNotificationTypeNone = 0, UIRemoteNotificationTypeBadge = 1 << 0, UIRemoteNotificationTypeSound = 1 << 1, UIRemoteNotificationTypeAlert = 1 << 2, UIRemoteNotificationTypeNewsstandContentAvailability = 1 << 3 } UIRemoteNotificationType;Constants
-
NoneUIRemoteNotificationTypeNoneThe app accepts no notifications.
Register for user notification settings using the
registerUserNotificationSettings:method insteadAvailable in iOS 3.0 and later.
Deprecated in iOS 8.0.
-
BadgeUIRemoteNotificationTypeBadgeThe app accepts notifications that badge the app icon.
Register for user notification settings using the
registerUserNotificationSettings:method insteadAvailable in iOS 3.0 and later.
Deprecated in iOS 8.0.
-
SoundUIRemoteNotificationTypeSoundThe app accepts alert sounds as notifications.
Register for user notification settings using the
registerUserNotificationSettings:method insteadAvailable in iOS 3.0 and later.
Deprecated in iOS 8.0.
-
AlertUIRemoteNotificationTypeAlertThe app accepts alert messages as notifications.
Register for user notification settings using the
registerUserNotificationSettings:method insteadAvailable in iOS 3.0 and later.
Deprecated in iOS 8.0.
-
NewsstandContentAvailabilityUIRemoteNotificationTypeNewsstandContentAvailabilityThe app accepts notifications that start the downloading of issue assets for Newsstand apps.
Register for user notification settings using the
registerUserNotificationSettings:method insteadAvailable in iOS 3.0 and later.
Deprecated in iOS 8.0.
Discussion
One or more of the values in the
UIRemoteNotificationTypebit mask are passed to iOS as the argument of theregisterForRemoteNotificationTypes:method. Thereafter, iOS filters notifications for the app based on these values. You can always get the current notification types by calling theenabledRemoteNotificationTypesmethod.Import Statement
Objective-C
@import UIKit;Swift
import UIKitAvailability
Available in iOS 3.0 and later.
-
-
The style of the device’s status bar.
Declaration
Swift
enum UIStatusBarStyle : Int { case Default case LightContent static var BlackTranslucent: UIStatusBarStyle { get } case BlackOpaque }Objective-C
typedef enum : NSInteger { UIStatusBarStyleDefault, UIStatusBarStyleLightContent, UIStatusBarStyleBlackTranslucent, UIStatusBarStyleBlackOpaque } UIStatusBarStyle;Constants
-
DefaultUIStatusBarStyleDefaultA dark status bar, intended for use on light backgrounds.
Available in iOS 2.0 and later.
-
LightContentUIStatusBarStyleLightContentA light status bar, intended for use on dark backgrounds.
Available in iOS 7.0 and later.
-
UIStatusBarStyleBlackTranslucentA transparent black style.
Use
UIStatusBarStyleLightContentinstead.Available in iOS 2.0 and later.
Deprecated in iOS 7.0.
-
UIStatusBarStyleBlackOpaqueAn opaque black style.
Use
UIStatusBarStyleLightContentinstead.Available in iOS 2.0 and later.
Deprecated in iOS 7.0.
Import Statement
Objective-C
@import UIKit;Swift
import UIKitAvailability
Available in iOS 2.0 and later.
-
-
The animation applied to the status bar as it is hidden or made visible.
Declaration
Swift
enum UIStatusBarAnimation : Int { case None case Fade case Slide }Objective-C
typedef enum : NSInteger { UIStatusBarAnimationNone, UIStatusBarAnimationFade, UIStatusBarAnimationSlide, } UIStatusBarAnimation;Constants
-
NoneUIStatusBarAnimationNoneNo animation is applied to the status bar as it is shown or hidden.
Available in iOS 3.2 and later.
-
FadeUIStatusBarAnimationFadeThe status bar fades in and out as it is shown or hidden, respectively.
Available in iOS 3.2 and later.
-
SlideUIStatusBarAnimationSlideThe status bar slides in or out as it is shown or hidden, respectively.
Available in iOS 3.2 and later.
Discussion
Constants of the
UIStatusBarAnimationtype are arguments of thesetStatusBarHidden:withAnimation:method.Import Statement
Objective-C
@import UIKit;Swift
import UIKitAvailability
Available in iOS 3.2 and later.
-
-
The running states of an app
Declaration
Swift
enum UIApplicationState : Int { case Active case Inactive case Background }Objective-C
typedef enum : NSInteger { UIApplicationStateActive, UIApplicationStateInactive, UIApplicationStateBackground } UIApplicationState;Constants
-
ActiveUIApplicationStateActiveThe app is running in the foreground and currently receiving events.
Available in iOS 4.0 and later.
-
InactiveUIApplicationStateInactiveThe app is running in the foreground but is not receiving events. This might happen as a result of an interruption or because the app is transitioning to or from the background.
Available in iOS 4.0 and later.
-
BackgroundUIApplicationStateBackgroundThe app is running in the background.
Available in iOS 4.0 and later.
Import Statement
Objective-C
@import UIKit;Swift
import UIKitAvailability
Available in iOS 4.0 and later.
-
-
Constants used when running in the background.
Declaration
Swift
let UIBackgroundTaskInvalid: UIBackgroundTaskIdentifier let UIMinimumKeepAliveTimeout: NSTimeIntervalObjective-C
const UIBackgroundTaskIdentifier UIBackgroundTaskInvalid; const NSTimeInterval UIMinimumKeepAliveTimeout;Constants
-
UIBackgroundTaskInvalidUIBackgroundTaskInvalidAn token indicating an invalid task request. This constant should be used to initialize variables or to check for errors.
Available in iOS 4.0 and later.
-
UIMinimumKeepAliveTimeoutUIMinimumKeepAliveTimeoutThe minimum amount of time (measured in seconds) an app may run a critical background task in the background.
Available in iOS 4.0 and later.
-
-
Constants that indicate the result of a background fetch operation.
Declaration
Swift
enum UIBackgroundFetchResult : UInt { case NewData case NoData case Failed }Objective-C
typedef enum : NSUInteger { UIBackgroundFetchResultNewData, UIBackgroundFetchResultNoData, UIBackgroundFetchResultFailed } UIBackgroundFetchResult;Constants
-
NewDataUIBackgroundFetchResultNewDataNew data was successfully downloaded.
Available in iOS 7.0 and later.
-
NoDataUIBackgroundFetchResultNoDataThere was no new data to download.
Available in iOS 7.0 and later.
-
FailedUIBackgroundFetchResultFailedAn attempt to download data was made but that attempt failed.
Available in iOS 7.0 and later.
Import Statement
Objective-C
@import UIKit;Swift
import UIKitAvailability
Available in iOS 7.0 and later.
-
-
Constants indicating fetch intervals for background downloads.
Declaration
Swift
let UIApplicationBackgroundFetchIntervalMinimum: NSTimeInterval let UIApplicationBackgroundFetchIntervalNever: NSTimeIntervalObjective-C
const NSTimeInterval UIApplicationBackgroundFetchIntervalMinimum; const NSTimeInterval UIApplicationBackgroundFetchIntervalNever;Constants
-
UIApplicationBackgroundFetchIntervalMinimumUIApplicationBackgroundFetchIntervalMinimumThe smallest fetch interval supported by the system.
Available in iOS 7.0 and later.
-
UIApplicationBackgroundFetchIntervalNeverUIApplicationBackgroundFetchIntervalNeverA fetch interval large enough to prevent fetch operations from occurring.
Available in iOS 7.0 and later.
-
-
Constants indicating whether background execution is enabled for the app.
Declaration
Swift
enum UIBackgroundRefreshStatus : Int { case Restricted case Denied case Available }Objective-C
typedef enum : NSUInteger { UIBackgroundRefreshStatusRestricted, UIBackgroundRefreshStatusDenied, UIBackgroundRefreshStatusAvailable } UIBackgroundRefreshStatus;Constants
-
RestrictedUIBackgroundRefreshStatusRestrictedBackground updates are unavailable and the user cannot enable them again. For example, this status can occur when parental controls are in effect for the current user.
Available in iOS 7.0 and later.
-
DeniedUIBackgroundRefreshStatusDeniedThe user explicitly disabled background behavior for this app or for the whole system.
Available in iOS 7.0 and later.
-
AvailableUIBackgroundRefreshStatusAvailableBackground updates are available for the app.
Available in iOS 7.0 and later.
Import Statement
Objective-C
@import UIKit;Swift
import UIKitAvailability
Available in iOS 7.0 and later.
-
-
The orientation of the app's user interface.
Declaration
Swift
enum UIInterfaceOrientation : Int { case Unknown case Portrait case PortraitUpsideDown case LandscapeLeft case LandscapeRight }Objective-C
typedef enum : NSInteger { UIInterfaceOrientationUnknown = UIDeviceOrientationUnknown, UIInterfaceOrientationPortrait = UIDeviceOrientationPortrait, UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown, UIInterfaceOrientationLandscapeLeft = UIDeviceOrientationLandscapeRight, UIInterfaceOrientationLandscapeRight = UIDeviceOrientationLandscapeLeft } UIInterfaceOrientation;Constants
-
UnknownUIInterfaceOrientationUnknownThe orientation of the device cannot be determined.
Available in iOS 8.0 and later.
-
PortraitUIInterfaceOrientationPortraitThe device is in portrait mode, with the device held upright and the home button on the bottom.
Available in iOS 2.0 and later.
-
PortraitUpsideDownUIInterfaceOrientationPortraitUpsideDownThe device is in portrait mode but upside down, with the device held upright and the home button at the top.
Available in iOS 2.0 and later.
-
LandscapeLeftUIInterfaceOrientationLandscapeLeftThe device is in landscape mode, with the device held upright and the home button on the left side.
Available in iOS 2.0 and later.
-
LandscapeRightUIInterfaceOrientationLandscapeRightThe device is in landscape mode, with the device held upright and the home button on the right side.
Available in iOS 2.0 and later.
Discussion
Starting in iOS 8, you should employ the
UITraitCollectionandUITraitEnvironmentAPIs, and size class properties as used in those APIs, instead of using UIInterfaceOrientation constants or otherwise writing your app in terms of interface orientation.In earlier versions of iOS, you used these constants in the
statusBarOrientationproperty and thesetStatusBarOrientation:animated:method. Notice thatUIDeviceOrientationLandscapeRightis assigned toUIInterfaceOrientationLandscapeLeftandUIDeviceOrientationLandscapeLeftis assigned toUIInterfaceOrientationLandscapeRight; the reason for this is that rotating the device requires rotating the content in the opposite direction.Import Statement
Objective-C
@import UIKit;Swift
import UIKitAvailability
Available in iOS 2.0 and later.
-
-
These constants are mask bits for specifying a view controller’s supported interface orientations.
Declaration
Swift
struct UIInterfaceOrientationMask : OptionSetType { init(rawValuerawValue: UInt) static var Portrait: UIInterfaceOrientationMask { get } static var LandscapeLeft: UIInterfaceOrientationMask { get } static var LandscapeRight: UIInterfaceOrientationMask { get } static var PortraitUpsideDown: UIInterfaceOrientationMask { get } static var Landscape: UIInterfaceOrientationMask { get } static var All: UIInterfaceOrientationMask { get } static var AllButUpsideDown: UIInterfaceOrientationMask { get } }Objective-C
typedef enum : NSUInteger { UIInterfaceOrientationMaskPortrait = (1 << UIInterfaceOrientationPortrait ), UIInterfaceOrientationMaskLandscapeLeft = (1 << UIInterfaceOrientationLandscapeLeft ), UIInterfaceOrientationMaskLandscapeRight = (1 << UIInterfaceOrientationLandscapeRight ), UIInterfaceOrientationMaskPortraitUpsideDown = (1 << UIInterfaceOrientationPortraitUpsideDown ), UIInterfaceOrientationMaskLandscape = (UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight ), UIInterfaceOrientationMaskAll = (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortraitUpsideDown ), UIInterfaceOrientationMaskAllButUpsideDown = (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight ), } UIInterfaceOrientationMask;Constants
-
PortraitUIInterfaceOrientationMaskPortraitThe view controller supports a portrait interface orientation.
Available in iOS 6.0 and later.
-
LandscapeLeftUIInterfaceOrientationMaskLandscapeLeftThe view controller supports a landscape-left interface orientation.
Available in iOS 6.0 and later.
-
LandscapeRightUIInterfaceOrientationMaskLandscapeRightThe view controller supports a landscape-right interface orientation.
Available in iOS 6.0 and later.
-
PortraitUpsideDownUIInterfaceOrientationMaskPortraitUpsideDownThe view controller supports an upside-down portrait interface orientation.
Available in iOS 6.0 and later.
-
LandscapeUIInterfaceOrientationMaskLandscapeThe view controller supports both landscape-left and landscape-right interface orientation.
Available in iOS 6.0 and later.
-
AllUIInterfaceOrientationMaskAllThe view controller supports all interface orientations.
Available in iOS 6.0 and later.
-
AllButUpsideDownUIInterfaceOrientationMaskAllButUpsideDownThe view controller supports all but the upside-down portrait interface orientation.
Available in iOS 6.0 and later.
Discussion
Starting in iOS 8, you should employ the
UITraitCollectionandUITraitEnvironmentAPIs, and size class properties as used in those APIs, instead of using UIInterfaceOrientation constants or otherwise writing your app in terms of interface orientation.In earlier versions of iOS, you returned these constants from the
supportedInterfaceOrientationsForWindow:method or when determining which orientations to support in your app’s view controllers.Import Statement
Objective-C
@import UIKit;Swift
import UIKitAvailability
Available in iOS 6.0 and later.
-
-
Specifies the directional flow of the user interface.
Declaration
Swift
enum UIUserInterfaceLayoutDirection : Int { case LeftToRight case RightToLeft }Objective-C
typedef enum : NSInteger { UIUserInterfaceLayoutDirectionLeftToRight, UIUserInterfaceLayoutDirectionRightToLeft, } UIUserInterfaceLayoutDirection;Constants
-
LeftToRightUIUserInterfaceLayoutDirectionLeftToRightThe layout direction is left to right.
Available in iOS 5.0 and later.
-
RightToLeftUIUserInterfaceLayoutDirectionRightToLeftThe layout direction right to left. This value is appropriate when running with localizations such as Arabic or Hebrew that should have the user interface layout origin on the right edge of the coordinate system.
Available in iOS 5.0 and later.
Discussion
One of these constants is returned by the
userInterfaceLayoutDirectionproperty. It indicates the directionality of the language in the user interface of the app.Import Statement
Objective-C
@import UIKit;Swift
import UIKitAvailability
Available in iOS 5.0 and later.
-
-
Constant used to open the app’s settings.
Declaration
Swift
let UIApplicationOpenSettingsURLString: StringObjective-C
NSString *const UIApplicationOpenSettingsURLString;Constants
-
UIApplicationOpenSettingsURLStringUIApplicationOpenSettingsURLStringUsed 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.Available in iOS 8.0 and later.
-
-
Keys used to access values in the
userInfodictionary of someUIApplication-posted notifications.Declaration
Swift
let UIApplicationStatusBarOrientationUserInfoKey: String let UIApplicationStatusBarFrameUserInfoKey: StringObjective-C
NSString *const UIApplicationStatusBarOrientationUserInfoKey; NSString *const UIApplicationStatusBarFrameUserInfoKey;Constants
-
UIApplicationStatusBarOrientationUserInfoKeyUIApplicationStatusBarOrientationUserInfoKeyA key whose value is an
NSNumberobject that encapsulates aUIInterfaceOrientationvalue indicating the current orientation (see UIInterfaceOrientation). This key is used withUIApplicationDidChangeStatusBarOrientationNotificationandUIApplicationWillChangeStatusBarOrientationNotificationnotifications.Available in iOS 2.0 and later.
-
UIApplicationStatusBarFrameUserInfoKeyUIApplicationStatusBarFrameUserInfoKeyA key whose value is an
NSValueobject that encapsulates aCGRectstructure expressing the location and size of the new status bar frame. This key is used withUIApplicationDidChangeStatusBarFrameNotificationandUIApplicationWillChangeStatusBarFrameNotificationnotifications.Available in iOS 2.0 and later.
-
-
Constants that indicate the user’s preferred font size.
Declaration
Swift
let UIContentSizeCategoryExtraSmall: String let UIContentSizeCategorySmall: String let UIContentSizeCategoryMedium: String let UIContentSizeCategoryLarge: String let UIContentSizeCategoryExtraLarge: String let UIContentSizeCategoryExtraExtraLarge: String let UIContentSizeCategoryExtraExtraExtraLarge: StringObjective-C
NSString *const UIContentSizeCategoryExtraSmall; NSString *const UIContentSizeCategorySmall; NSString *const UIContentSizeCategoryMedium; NSString *const UIContentSizeCategoryLarge; NSString *const UIContentSizeCategoryExtraLarge; NSString *const UIContentSizeCategoryExtraExtraLarge; NSString *const UIContentSizeCategoryExtraExtraExtraLarge;Constants
-
UIContentSizeCategoryExtraSmallUIContentSizeCategoryExtraSmallAn extra small font.
Available in iOS 7.0 and later.
-
UIContentSizeCategorySmallUIContentSizeCategorySmallA small font.
Available in iOS 7.0 and later.
-
UIContentSizeCategoryMediumUIContentSizeCategoryMediumA medium-sized font.
Available in iOS 7.0 and later.
-
UIContentSizeCategoryLargeUIContentSizeCategoryLargeA large font.
Available in iOS 7.0 and later.
-
UIContentSizeCategoryExtraLargeUIContentSizeCategoryExtraLargeAn extra large font.
Available in iOS 7.0 and later.
-
UIContentSizeCategoryExtraExtraLargeUIContentSizeCategoryExtraExtraLargeAn increasingly large font.
Available in iOS 7.0 and later.
-
UIContentSizeCategoryExtraExtraExtraLargeUIContentSizeCategoryExtraExtraExtraLargeThe largest font option.
Available in iOS 7.0 and later.
-
-
Constants that indicate the preferred font sizes when accessibility is enabled.
Declaration
Swift
let UIContentSizeCategoryAccessibilityMedium: String let UIContentSizeCategoryAccessibilityLarge: String let UIContentSizeCategoryAccessibilityExtraLarge: String let UIContentSizeCategoryAccessibilityExtraExtraLarge: String let UIContentSizeCategoryAccessibilityExtraExtraExtraLarge: StringObjective-C
NSString *const UIContentSizeCategoryAccessibilityMedium; NSString *const UIContentSizeCategoryAccessibilityLarge; NSString *const UIContentSizeCategoryAccessibilityExtraLarge; NSString *const UIContentSizeCategoryAccessibilityExtraExtraLarge; NSString *const UIContentSizeCategoryAccessibilityExtraExtraExtraLarge;Constants
-
UIContentSizeCategoryAccessibilityMediumUIContentSizeCategoryAccessibilityMediumA medium font size reflecting the current accessibility settings.
Available in iOS 7.0 and later.
-
UIContentSizeCategoryAccessibilityLargeUIContentSizeCategoryAccessibilityLargeA large font size reflecting the current accessibility settings.
Available in iOS 7.0 and later.
-
UIContentSizeCategoryAccessibilityExtraLargeUIContentSizeCategoryAccessibilityExtraLargeA medium font size reflecting the current accessibility settings.
Available in iOS 7.0 and later.
-
UIContentSizeCategoryAccessibilityExtraExtraLargeUIContentSizeCategoryAccessibilityExtraExtraLargeA medium font size reflecting the current accessibility settings.
Available in iOS 7.0 and later.
-
UIContentSizeCategoryAccessibilityExtraExtraExtraLargeUIContentSizeCategoryAccessibilityExtraExtraExtraLargeA medium font size reflecting the current accessibility settings.
Available in iOS 7.0 and later.
-
-
Key identifying the new content size category.
Declaration
Swift
let UIContentSizeCategoryNewValueKey: StringObjective-C
NSString *const UIContentSizeCategoryNewValueKey;Constants
-
UIContentSizeCategoryNewValueKeyUIContentSizeCategoryNewValueKeyA key whose value is an
NSStringobject reflecting the new value of thepreferredContentSizeCategoryproperty.Available in iOS 7.0 and later.
-
-
Constants that identify extension points you want to disallow in your app.
Declaration
Swift
let UIApplicationKeyboardExtensionPointIdentifier: StringObjective-C
NSString *const UIApplicationKeyboardExtensionPointIdentifier;Constants
-
UIApplicationKeyboardExtensionPointIdentifierUIApplicationKeyboardExtensionPointIdentifierThe identifier for custom keyboards. To reject the use of custom keyboards in your app, specify this constant in your implementation of the
application:shouldAllowExtensionPointIdentifier:delegate method.Available in iOS 8.0 and later.
Discussion
In iOS 8.0, the only app extension type you can disallow is the custom keyboard.
-
-
Mode while tracking in controls is taking place.
Declaration
Swift
let UITrackingRunLoopMode: StringObjective-C
UIKIT_EXTERN NSString *UITrackingRunLoopMode;Constants
-
The following constant defines an exception that can be thrown by the app.
Declaration
Swift
let UIApplicationInvalidInterfaceOrientationException: StringObjective-C
NSString *const UIApplicationInvalidInterfaceOrientationException;Constants
-
UIApplicationInvalidInterfaceOrientationExceptionUIApplicationInvalidInterfaceOrientationExceptionThis exception is thrown if a view controller or the app returns
0instead of a valid set of supported interface orientation values. It is also thrown if the orientation returned by a view controller’spreferredInterfaceOrientationForPresentationmethod does not match one of the view controller’s supported orientations.Available in iOS 6.0 and later.
-
-
UIApplicationBackgroundRefreshStatusDidChangeNotification UIApplicationBackgroundRefreshStatusDidChangeNotificationPosted when the app’s status for downloading content in the background changes.
The system sends this notification when the
backgroundRefreshStatusproperty of the app object changes. That property can change in response to the user disabling multitasking support for the app. Theobjectof the notification is theUIApplicationobject. There is nouserInfodictionary.Declaration
Swift
let UIApplicationBackgroundRefreshStatusDidChangeNotification: StringImport Statement
Objective-C
@import UIKit;Swift
import UIKitAvailability
Available in iOS 7.0 and later.
-
Posted when the app becomes active.
An app is active when it is receiving events. An active app can be said to have focus. It gains focus after being launched, loses focus when an overlay window pops up or when the device is locked, and gains focus when the device is unlocked.
Declaration
Swift
let UIApplicationDidBecomeActiveNotification: StringImport Statement
Objective-C
@import UIKit;Swift
import UIKitAvailability
Available in iOS 2.0 and later.
-
Posted when the frame of the status bar changes.
The
userInfodictionary contains anNSValueobject that encapsulates aCGRectstructure expressing the location and size of the new status bar frame. UseUIApplicationStatusBarFrameUserInfoKeyto access this value.Declaration
Swift
let UIApplicationDidChangeStatusBarFrameNotification: StringImport Statement
Objective-C
@import UIKit;Swift
import UIKitAvailability
Available in iOS 2.0 and later.
-
UIApplicationDidChangeStatusBarOrientationNotification UIApplicationDidChangeStatusBarOrientationNotificationPosted when the orientation of the app’s user interface changes.
The
userInfodictionary contains anNSNumberobject that encapsulates aUIInterfaceOrientationvalue (see UIInterfaceOrientation). UseUIApplicationStatusBarOrientationUserInfoKeyto access this valueDeclaration
Swift
let UIApplicationDidChangeStatusBarOrientationNotification: StringImport Statement
Objective-C
@import UIKit;Swift
import UIKitAvailability
Available in iOS 2.0 and later.
-
Posted when the app enters the background.
The
objectof the notification is theUIApplicationobject. There is nouserInfodictionary.Declaration
Swift
let UIApplicationDidEnterBackgroundNotification: StringImport Statement
Objective-C
@import UIKit;Swift
import UIKitAvailability
Available in iOS 4.0 and later.
-
Posted immediately after the app finishes launching.
If the app was launched as a result of in remote notification targeted at it or because another app opened a URL resource claimed the posting app (the notification
object), this notification contains auserInfodictionary. You can access the contents of the dictionary using theUIApplicationLaunchOptionsURLKeyandUIApplicationLaunchOptionsSourceApplicationKeyconstants (for URLs), theUIApplicationLaunchOptionsRemoteNotificationKeyconstant (for remote notifications), and theUIApplicationLaunchOptionsLocalNotificationKeyconstant (for local notifications). If the notification was posted for a normal app launch, there is nouserInfodictionary.Declaration
Swift
let UIApplicationDidFinishLaunchingNotification: StringImport Statement
Objective-C
@import UIKit;Swift
import UIKitAvailability
Available in iOS 2.0 and later.
-
Posted when the app receives a warning from the operating system about low memory availability.
This notification does not contain a
userInfodictionary.Declaration
Swift
let UIApplicationDidReceiveMemoryWarningNotification: StringImport Statement
Objective-C
@import UIKit;Swift
import UIKitAvailability
Available in iOS 2.0 and later.
-
Posted when the protected files become available for your code to access.
This notification does not contain a
userInfodictionary.Declaration
Swift
let UIApplicationProtectedDataDidBecomeAvailable: StringImport Statement
Objective-C
@import UIKit;Swift
import UIKitAvailability
Available in iOS 4.0 and later.
-
Posted shortly before protected files are locked down and become inaccessible.
Upon receiving this notification, clients should release any references to protected files. This notification does not contain a
userInfodictionary.Declaration
Swift
let UIApplicationProtectedDataWillBecomeUnavailable: StringImport Statement
Objective-C
@import UIKit;Swift
import UIKitAvailability
Available in iOS 4.0 and later.
-
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.
This notification does not contain a
userInfodictionary.Declaration
Swift
let UIApplicationSignificantTimeChangeNotification: StringImport Statement
Objective-C
@import UIKit;Swift
import UIKitAvailability
Available in iOS 2.0 and later.
-
Posted when the user presses the Home and Lock buttons to take a screenshot.
This notification does not contain a
userInfodictionary. This notification is posted after the screenshot is taken.Declaration
Swift
let UIApplicationUserDidTakeScreenshotNotification: StringImport Statement
Objective-C
@import UIKit;Swift
import UIKitAvailability
Available in iOS 7.0 and later.
-
UIApplicationWillChangeStatusBarOrientationNotification UIApplicationWillChangeStatusBarOrientationNotificationPosted when the app is about to change the orientation of its interface.
The userInfo dictionary contains an
NSNumberthat encapsulates aUIInterfaceOrientationvalue (see UIInterfaceOrientation). UseUIApplicationStatusBarOrientationUserInfoKeyto access this value.Declaration
Swift
let UIApplicationWillChangeStatusBarOrientationNotification: StringImport Statement
Objective-C
@import UIKit;Swift
import UIKitAvailability
Available in iOS 2.0 and later.
-
Posted when the app is about to change the frame of the status bar.
The
userInfodictionary contains anNSValueobject that encapsulates aCGRectstructure expressing the location and size of the new status bar frame. UseUIApplicationStatusBarFrameUserInfoKeyto access this value.Declaration
Swift
let UIApplicationWillChangeStatusBarFrameNotification: StringImport Statement
Objective-C
@import UIKit;Swift
import UIKitAvailability
Available in iOS 2.0 and later.
-
Posted shortly before an app leaves the background state on its way to becoming the active app.
The
objectof the notification is theUIApplicationobject. There is nouserInfodictionary.Declaration
Swift
let UIApplicationWillEnterForegroundNotification: StringImport Statement
Objective-C
@import UIKit;Swift
import UIKitAvailability
Available in iOS 4.0 and later.
-
Posted when the app is no longer active and loses focus.
An app is active when it is receiving events. An active app can be said to have focus. It gains focus after being launched, loses focus when an overlay window pops up or when the device is locked, and gains focus when the device is unlocked.
Declaration
Swift
let UIApplicationWillResignActiveNotification: StringImport Statement
Objective-C
@import UIKit;Swift
import UIKitAvailability
Available in iOS 2.0 and later.
-
Posted when the app is about to terminate.
This notification is associated with the delegate
applicationWillTerminate:method. This notification does not contain auserInfodictionary.Declaration
Swift
let UIApplicationWillTerminateNotification: StringImport Statement
Objective-C
@import UIKit;Swift
import UIKitAvailability
Available in iOS 2.0 and later.
-
Posted when the user changes the preferred content size setting.
This notification is sent when the value in the
preferredContentSizeCategoryproperty changes. TheuserInfodictionary of the notification contains theUIContentSizeCategoryNewValueKeykey, which reflects the new setting.Declaration
Swift
let UIContentSizeCategoryDidChangeNotification: StringImport Statement
Objective-C
@import UIKit;Swift
import UIKitAvailability
Available in iOS 7.0 and later.
Copyright © 2015 Apple Inc. All rights reserved. Terms of Use | Privacy Policy | Updated: 2015-10-21
