iOS Developer Library

Developer

UIKit Framework Reference UIApplication Class Reference

Options
Deployment Target:

On This Page
Language:

UIApplication

Inheritance


Conforms To


Import Statement


Swift

import UIKit

Objective-C

@import UIKit;

Availability


Available in iOS 2.0 and later.

The UIApplication class provides a centralized point of control and coordination for apps running on iOS. Every app must have exactly one instance of UIApplication (or a subclass of UIApplication). When an app is launched, the UIApplicationMain function is called; among its other tasks, this function creates a singleton UIApplication object. Thereafter you access this object by invoking the sharedApplication class method.

A major role of a UIApplication object is to handle the initial routing of incoming user events. It also dispatches action messages forwarded to it by control objects (UIControl) to the appropriate target objects. In addition, the UIApplication object maintains a list of all the windows (UIWindow objects) currently open in the app, so through those it can retrieve any of the app’s UIView objects. The app object is typically assigned a delegate, an object that the app informs 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 opening an email URL with this method may cause the mail client to launch and display the message.

The programmatic interfaces of UIApplication allow you to manage behavior that is specific to the device. Use this object to do the following:

  • Control the app’s response to changes in interface orientation.

  • Temporarily suspend incoming touch events.

  • Turn proximity sensing (of the user’s face) off and on again.

  • Register for remote notifications.

  • Trigger the undo-redo UI (applicationSupportsShakeToEdit).

  • Determine whether an installed app can open a URL (canOpenURL:).

  • Extend the execution of the app so that it can finish a task in the background.

  • Schedule and cancel local notifications.

  • Coordinate the reception of remote-control events.

  • Perform app-level state restoration tasks.

UIApplication defines a delegate that must adopt the UIApplicationDelegate protocol and implement some of the protocol methods.

Subclassing Notes

Most apps should never need to subclass the UIApplication class. Most apps use an app delegate to manage interactions between the system and the app.

The only situation where you might need to subclass UIApplication is when you are implementing a custom event or action dispatching mechanism. In that situation, you might override the sendEvent: or sendAction:to:from:forEvent: methods to implement that mechanism. However, the cases where this is required are very rare and should be avoided whenever possible.

  • Returns the singleton app instance.

    Declaration

    Swift

    class func sharedApplication() -> UIApplication

    Objective-C

    + (UIApplication *)sharedApplication

    Return Value

    The app instance is created in the UIApplicationMain function.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

    Not available in app extensions.

  • delegate delegate Property

    The delegate of the app object.

    Declaration

    Swift

    unowned(unsafe) var delegate: UIApplicationDelegate?

    Objective-C

    @property(nonatomic, assign) id< UIApplicationDelegate > delegate

    Discussion

    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 UIApplicationDelegate formal protocol.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • keyWindow keyWindow Property

    The app's key window. (read-only)

    Declaration

    Swift

    var keyWindow: UIWindow? { get }

    Objective-C

    @property(nonatomic, readonly) UIWindow *keyWindow

    Discussion

    This property holds the UIWindow object in the windows array that is most recently sent the makeKeyAndVisible message.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

    See Also

    windows

  • windows windows Property

    The app's visible and hidden windows. (read-only)

    Declaration

    Swift

    var windows: [AnyObject] { get }

    Objective-C

    @property(nonatomic, readonly) NSArray *windows

    Discussion

    This property contains the UIWindow objects 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.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

    See Also

    keyWindow

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

    Declaration

    Swift

    func sendEvent(_ event: UIEvent)

    Objective-C

    - (void)sendEvent:(UIEvent *)event

    Parameters

    event

    A UIEvent object encapsulating the information about an event, including the touches involved.

    Discussion

    Subclasses may override this method to intercept incoming events. Any intercepted events should be dispatched by calling [super sendEvent:event] after examining the intercepted event.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

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

    Declaration

    Swift

    func sendAction(_ action: Selector, to target: AnyObject?, from sender: AnyObject?, forEvent event: UIEvent?) -> Bool

    Objective-C

    - (BOOL)sendAction:(SEL)action to:(id)target from:(id)sender forEvent:(UIEvent *)event

    Parameters

    action

    A selector identifying an action method. See the discussion for information on the permitted selector forms.

    target

    The object to receive the action message. If target is nil, the app sends the message to the first responder, from whence it progresses up the responder chain until it is handled.

    sender

    The object that is sending the action message. The default sender is the UIControl object that invokes this method.

    event

    A UIEvent object that encapsulates information about the event originating the action message.

    Return Value

    YEStrue if a responder object handled the action message, NOfalse if no object in the responder chain handled the message.

    Discussion

    Normally, this method is invoked by a UIControl object 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 UIControl object) 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

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

    See Also

    – sendEvent:

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

    Declaration

    Swift

    func beginIgnoringInteractionEvents()

    Objective-C

    - (void)beginIgnoringInteractionEvents

    Discussion

    You typically call this method before starting an animation or transition. Calls are nested with the endIgnoringInteractionEvents method.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

    Not available in app extensions.

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

    Declaration

    Swift

    func endIgnoringInteractionEvents()

    Objective-C

    - (void)endIgnoringInteractionEvents

    Discussion

    You typically call this method when, after calling the beginIgnoringInteractionEvents method, the animation or transition concludes. Nested calls of this method should match nested calls of the beginIgnoringInteractionEvents method.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

    Not available in app extensions.

  • Returns whether the receiver is ignoring events initiated by touches on the screen.

    Declaration

    Swift

    func isIgnoringInteractionEvents() -> Bool

    Objective-C

    - (BOOL)isIgnoringInteractionEvents

    Return Value

    YEStrue if the receiver is ignoring interaction events; otherwise NOfalse. The method returns YEStrue if the nested beginIgnoringInteractionEvents and endIgnoringInteractionEvents calls are at least one level deep.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    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: Bool

    Objective-C

    @property(nonatomic) BOOL applicationSupportsShakeToEdit

    Discussion

    The default value is YEStrue. Set the property to NOfalse if you don’t want your app to display the Undo and Redo buttons when users shake the device.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 3.0 and later.

  • Opens the resource at the specified URL.

    Declaration

    Swift

    func openURL(_ url: NSURL) -> Bool

    Objective-C

    - (BOOL)openURL:(NSURL *)url

    Parameters

    url

    An object representing a URL (Universal Resource Locator). UIKit supports many schemes, including http, https, tel, facetime, and mailto schemes.

    Return Value

    YEStrue if the resource located by the URL was successfully opened; otherwise NOfalse.

    Discussion

    The URL can locate a resource in the same or other app. If the resource is another app, invoking this method may cause the calling app to quit so the other one can be launched.

    You may call canOpenURL: before calling this one to verify that there is an app that can handle it.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

    Not available in app extensions.

    See Also

    application:handleOpenURL: (UIApplicationDelegate)

  • Returns whether an app can open a given URL resource.

    Declaration

    Swift

    func canOpenURL(_ url: NSURL) -> Bool

    Objective-C

    - (BOOL)canOpenURL:(NSURL *)url

    Parameters

    url

    A URL object that identifies a given resource. The URL’s scheme—possibly a custom scheme—identifies which app can handle the URL.

    Return Value

    NOfalse if no app is available that will accept the URL; otherwise, returns YEStrue.

    Discussion

    This method guarantees that that if openURL: is called, another app will be launched to handle it. It does not guarantee that the full URL is valid.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 3.0 and later.

  • Registers your preferred options for notifying the user.

    Declaration

    Swift

    func registerUserNotificationSettings(_ notificationSettings: UIUserNotificationSettings)

    Objective-C

    - (void)registerUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings

    Parameters

    notificationSettings

    The 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 applicationIconBadgeNumber property 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 notificationSettings object.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 8.0 and later.

  • Returns the user notification settings for the app.

    Declaration

    Swift

    func currentUserNotificationSettings() -> UIUserNotificationSettings!

    Objective-C

    - (UIUserNotificationSettings *)currentUserNotificationSettings

    Return 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.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 8.0 and later.

  • Register to receive remote notifications via Apple Push Notification service.

    Declaration

    Swift

    func registerForRemoteNotifications()

    Objective-C

    - (void)registerForRemoteNotifications

    Discussion

    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’s application: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 the currentUserNotificationSettings method.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 8.0 and later.

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

    Declaration

    Swift

    func unregisterForRemoteNotifications()

    Objective-C

    - (void)unregisterForRemoteNotifications

    Discussion

    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.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 3.0 and later.

  • Returns a Boolean indicating whether the app is currently registered for remote notifications.

    Declaration

    Swift

    func isRegisteredForRemoteNotifications() -> Bool

    Objective-C

    - (BOOL)isRegisteredForRemoteNotifications

    Return Value

    YEStrue if the app is registered for remote notifications and received its device token or NOfalse if 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 registerForRemoteNotifications method. 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.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 8.0 and later.

  • The runtime state of the app. (read-only)

    Declaration

    Swift

    var applicationState: UIApplicationState { get }

    Objective-C

    @property(nonatomic, readonly) UIApplicationState applicationState

    Discussion

    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.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    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 backgroundTimeRemaining

    Discussion

    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.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    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 backgroundRefreshStatus

    Discussion

    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.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    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)minimumBackgroundFetchInterval

    Parameters

    minimumBackgroundFetchInterval

    The 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 UIBackgroundModes key with the fetch value in its Info.plist file.

    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.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    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?, expirationHandler handler: (() -> Void)?) -> UIBackgroundTaskIdentifier

    Objective-C

    - (UIBackgroundTaskIdentifier)beginBackgroundTaskWithName:(NSString *)taskName expirationHandler:(void (^)(void))handler

    Parameters

    taskName

    The name to display in the debugger when viewing the background task. If you specify nil for this parameter, this method generates a name based on the name of the calling function or method.

    handler

    A 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 returns UIBackgroundTaskInvalid if 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.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.

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

    Declaration

    Swift

    func beginBackgroundTaskWithExpirationHandler(_ handler: () -> Void) -> UIBackgroundTaskIdentifier

    Objective-C

    - (UIBackgroundTaskIdentifier)beginBackgroundTaskWithExpirationHandler:(void (^)(void))handler

    Parameters

    handler

    A 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 returns UIBackgroundTaskInvalid if 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 the backgroundTimeRemaining property.) If you do not call endBackgroundTask: for each task before time expires, the system kills the app. If you provide a block object in the handler parameter, 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.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 4.0 and later.

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

    Declaration

    Swift

    func endBackgroundTask(_ identifier: UIBackgroundTaskIdentifier)

    Objective-C

    - (void)endBackgroundTask:(UIBackgroundTaskIdentifier)identifier

    Parameters

    identifier

    An 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.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 4.0 and later.

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

    Declaration

    Swift

    func setKeepAliveTimeout(_ timeout: NSTimeInterval, handler keepAliveHandler: (() -> Void)?) -> Bool

    Objective-C

    - (BOOL)setKeepAliveTimeout:(NSTimeInterval)timeout handler:(void (^)(void))keepAliveHandler

    Parameters

    timeout

    The 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.

    keepAliveHandler

    A block that performs the tasks needed to maintain your VoIP network connection. Setting this parameter to nil releases the current handler block and prevents UIKit from scheduling the next wake.

    Return Value

    YEStrue if the handler was installed or NOfalse if it was not.

    Discussion

    In iOS 8 and later, voice-over-IP (VoIP) apps register for UIRemoteNotificationTypeVoIP remote 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 voip value in the array associated with the UIBackgroundModes key in its Info.plist file. Calling this method replaces the previously installed handler and timeout values, if any.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 4.0 and later.

  • Removes a previously installed periodic handler block.

    Declaration

    Swift

    func clearKeepAliveTimeout()

    Objective-C

    - (void)clearKeepAliveTimeout

    Discussion

    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.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 4.0 and later.

  • Tells the app that your code is restoring state asynchronously.

    Declaration

    Swift

    func extendStateRestoration()

    Objective-C

    - (void)extendStateRestoration

    Discussion

    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 completeStateRestoration method.

    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 completeStateRestoration method 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.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 6.0 and later.

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

    Declaration

    Swift

    func completeStateRestoration()

    Objective-C

    - (void)completeStateRestoration

    Discussion

    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 extendStateRestoration method 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.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 6.0 and later.

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

    Declaration

    Swift

    func ignoreSnapshotOnNextApplicationLaunch()

    Objective-C

    - (void)ignoreSnapshotOnNextApplicationLaunch

    Discussion

    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.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.

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

    Declaration

    Swift

    class func registerObjectForStateRestoration(_ object: UIStateRestoring, restorationIdentifier restorationIdentifier: String)

    Objective-C

    + (void)registerObjectForStateRestoration:(id<UIStateRestoring>)object restorationIdentifier:(NSString *)restorationIdentifier

    Parameters

    object

    The object to be registered with the restoration archive. The object must adopt the UIStateRestoring protocol. This parameter must not be nil.

    restorationIdentifier

    The 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.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.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 protectedDataAvailable

    Discussion

    The value of this property is NOfalse if data protection is enabled and the device is currently locked. The value of this property is set to YEStrue if the device is unlocked or if content protection is not enabled.

    When the value of this property is NOfalse, files that were assigned the NSFileProtectionComplete or NSFileProtectionCompleteUnlessOpen protection key cannot be read or written by your app. The user must unlock the device before your app can access them.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 4.0 and later.

  • Tells the app to begin receiving remote-control events.

    Declaration

    Swift

    func beginReceivingRemoteControlEvents()

    Objective-C

    - (void)beginReceivingRemoteControlEvents

    Discussion

    In iOS 7.1 and later, use the shared MPRemoteCommandCenter object 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.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 4.0 and later.

  • Tells the app to stop receiving remote-control events.

    Declaration

    Swift

    func endReceivingRemoteControlEvents()

    Objective-C

    - (void)endReceivingRemoteControlEvents

    Discussion

    In iOS 7.1 and later, use the shared MPRemoteCommandCenter object 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.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 4.0 and later.

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

    Declaration

    Swift

    var idleTimerDisabled: Bool

    Objective-C

    @property(nonatomic, getter=isIdleTimerDisabled) BOOL idleTimerDisabled

    Discussion

    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 to YEStrue, disable the “idle timer” to avert system sleep.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

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

    Declaration

    Swift

    func setStatusBarHidden(_ hidden: Bool, withAnimation animation: UIStatusBarAnimation)

    Objective-C

    - (void)setStatusBarHidden:(BOOL)hidden withAnimation:(UIStatusBarAnimation)animation

    Parameters

    hidden

    YEStrue to hide the status bar, NOfalse to show the status bar.

    animation

    A 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 UIStatusBarAnimation type for more information.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 3.2 and later.

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

    Declaration

    Swift

    var statusBarHidden: Bool

    Objective-C

    @property(nonatomic, getter=isStatusBarHidden) BOOL statusBarHidden

    Return Value

    YEStrue means the status bar is hidden; NOfalse means it's visible.

    Discussion

    Changing the value of this property changes the visibility of the status bar immediately—that is, without animations.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

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

    Declaration

    Swift

    func setStatusBarStyle(_ statusBarStyle: UIStatusBarStyle, animated animated: Bool)

    Objective-C

    - (void)setStatusBarStyle:(UIStatusBarStyle)statusBarStyle animated:(BOOL)animated

    Parameters

    statusBarStyle

    A constant that specifies a style for the status bar. See the descriptions of the constants in UIStatusBarStyle for details.

    animated

    YEStrue if the transition to the new style should be animated; otherwise NOfalse .

    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 UIViewControllerBasedStatusBarAppearance key with a value of NOfalse to your app’s Info.plist file, but doing so is not recommended.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

    See Also

    statusBarStyle

  • The current style of the status bar.

    Declaration

    Swift

    var statusBarStyle: UIStatusBarStyle

    Objective-C

    @property(nonatomic) UIStatusBarStyle statusBarStyle

    Discussion

    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.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • The frame rectangle defining the area of the status bar. (read-only)

    Declaration

    Swift

    var statusBarFrame: CGRect { get }

    Objective-C

    @property(nonatomic, readonly) CGRect statusBarFrame

    Discussion

    The value of this property is CGRectZero if the status bar is hidden.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

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

    Declaration

    Swift

    var networkActivityIndicatorVisible: Bool

    Objective-C

    @property(nonatomic, getter=isNetworkActivityIndicatorVisible) BOOL networkActivityIndicatorVisible

    Discussion

    Specify YEStrue if the app should show network activity and NOfalse if it should not. The default value is NOfalse. A spinning indicator in the status bar shows network activity. The app may explicitly hide or show this indicator.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    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: Int

    Objective-C

    @property(nonatomic) NSInteger applicationIconBadgeNumber

    Discussion

    Set to 0 (zero) to hide the badge number. The default value of this property is 0.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    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 userInterfaceLayoutDirection

    Discussion

    This method specifies the general user interface layout flow direction. See UIUserInterfaceLayoutDirection for a description of the constants returned by this property.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    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 *preferredContentSizeCategory

    Discussion

    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 UIContentSizeCategoryDidChangeNotification notification so that observers can respond accordingly.

    For a list of possible values, see Content Size Category Constants and Accessibility Content Size Category Constants.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • 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 *)image

    Parameters

    image

    An image to use as the icon of a Newsstand app. Pass nil to 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.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 5.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) -> Int

    Objective-C

    - (NSUInteger)supportedInterfaceOrientationsForWindow:(UIWindow *)window

    Parameters

    window

    The window whose default interface orientations you want to retrieve.

    Return Value

    A bit mask specifying which orientations are supported. See “UIInterfaceOrientationMask” for valid bit-mask values. The value returned by this method must not be 0.

    Discussion

    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 defined in the UISupportedInterfaceOrientations key of the Info.plist file. 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.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 6.0 and later.

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

    Declaration

    Swift

    func setStatusBarOrientation(_ interfaceOrientation: UIInterfaceOrientation, animated animated: Bool)

    Objective-C

    - (void)setStatusBarOrientation:(UIInterfaceOrientation)interfaceOrientation animated:(BOOL)animated

    Parameters

    interfaceOrientation

    A specific orientation of the status bar. See UIInterfaceOrientation for details. The default value is UIInterfaceOrientationPortrait.

    animated

    YEStrue if the transition to the new orientation should be animated; NOfalse if it should be immediate, without animation.

    Discussion

    Calling this method changes the value of the statusBarOrientation property and rotates the status bar, animating the transition if animated is YEStrue . 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.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • The current orientation of the app's status bar.

    Declaration

    Swift

    var statusBarOrientation: UIInterfaceOrientation

    Objective-C

    @property(nonatomic) UIInterfaceOrientation statusBarOrientation

    Discussion

    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.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.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 statusBarOrientationAnimationDuration

    Discussion

    You should double the value of this property for a 180 degree orientation change in the status bar.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

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

    Deprecation Statement

    Use the registerForRemoteNotifications method instead.

    Declaration

    Swift

    func registerForRemoteNotificationTypes(_ types: UIRemoteNotificationType)

    Objective-C

    - (void)registerForRemoteNotificationTypes:(UIRemoteNotificationType)types

    Parameters

    types

    A 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 the application: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 enabledRemoteNotificationTypes method.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    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 isRegisteredForRemoteNotifications method instead.

    Declaration

    Swift

    func enabledRemoteNotificationTypes() -> UIRemoteNotificationType

    Objective-C

    - (UIRemoteNotificationType)enabledRemoteNotificationTypes

    Return Value

    A bit mask whose values indicate the types of notifications the user has requested for the app. See UIRemoteNotificationType for 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.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    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 proximityMonitoringEnabled and proximityState properties of the UIDevice class instead.

    Declaration

    Objective-C

    @property(nonatomic, getter=isProximitySensingEnabled) BOOL proximitySensingEnabled

    Discussion

    YEStrue if proximity sensing is enabled; otherwise NOfalse. 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.

    Import Statement

    Objective-C

    @import UIKit;

    Availability

    Available in iOS 2.0 and later.

    Deprecated in iOS 3.0.

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

    Deprecation Statement

    Use the setStatusBarHidden:withAnimation: method instead.

    Declaration

    Objective-C

    - (void)setStatusBarHidden:(BOOL)hidden animated:(BOOL)animated

    Parameters

    hidden

    YEStrue if the status bar should be hidden, NOfalse if it should be visible. The default value is NOfalse.

    animated

    YEStrue if the transition to or from a hidden state should be animated, NOfalse otherwise.

    Discussion

    The animation fades the status bar out or in at the top of the interface, depending on the value of hidden.

    Import Statement

    Objective-C

    @import UIKit;

    Availability

    Available in iOS 2.0 and later.

    Deprecated in iOS 3.2.

    See Also

    statusBarHidden

Data Types

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

    Declaration

    Swift

    typealias UIBackgroundTaskIdentifier = Int

    Objective-C

    typedef NSUInteger UIBackgroundTaskIdentifier;

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    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 : RawOptionSetType { init(_ rawValue: UInt) init(rawValue rawValue: 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

    • None

      UIRemoteNotificationTypeNone

      The app accepts no notifications.

      Register for user notification settings using the registerUserNotificationSettings: method instead

      Available in iOS 3.0 and later.

      Deprecated in iOS 8.0.

    • Badge

      UIRemoteNotificationTypeBadge

      The app accepts notifications that badge the app icon.

      Register for user notification settings using the registerUserNotificationSettings: method instead

      Available in iOS 3.0 and later.

      Deprecated in iOS 8.0.

    • Sound

      UIRemoteNotificationTypeSound

      The app accepts alert sounds as notifications.

      Register for user notification settings using the registerUserNotificationSettings: method instead

      Available in iOS 3.0 and later.

      Deprecated in iOS 8.0.

    • Alert

      UIRemoteNotificationTypeAlert

      The app accepts alert messages as notifications.

      Register for user notification settings using the registerUserNotificationSettings: method instead

      Available in iOS 3.0 and later.

      Deprecated in iOS 8.0.

    • NewsstandContentAvailability

      UIRemoteNotificationTypeNewsstandContentAvailability

      The app accepts notifications that start the downloading of issue assets for Newsstand apps.

      Register for user notification settings using the registerUserNotificationSettings: method instead

      Available in iOS 3.0 and later.

      Deprecated in iOS 8.0.

    Discussion

    One or more of the values in the UIRemoteNotificationType bit mask are passed to iOS as the argument of the registerForRemoteNotificationTypes: method. Thereafter, iOS filters notifications for the app based on these values. You can always get the current notification types by calling the enabledRemoteNotificationTypes method.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 3.0 and later.

  • The style of the device’s status bar.

    Declaration

    Swift

    enum UIStatusBarStyle : Int { case Default case LightContent case BlackOpaque }

    Objective-C

    typedef enum : NSInteger { UIStatusBarStyleDefault, UIStatusBarStyleLightContent, UIStatusBarStyleBlackTranslucent, UIStatusBarStyleBlackOpaque } UIStatusBarStyle;

    Constants

    • Default

      UIStatusBarStyleDefault

      A dark status bar, intended for use on light backgrounds.

      Available in iOS 2.0 and later.

    • LightContent

      UIStatusBarStyleLightContent

      A light status bar, intended for use on dark backgrounds.

      Available in iOS 7.0 and later.

    • UIStatusBarStyleBlackTranslucent

      UIStatusBarStyleBlackTranslucent

      A transparent black style.

      Use UIStatusBarStyleLightContent instead.

      Available in iOS 2.0 and later.

      Deprecated in iOS 7.0.

    • UIStatusBarStyleBlackOpaque

      UIStatusBarStyleBlackOpaque

      An opaque black style.

      Use UIStatusBarStyleLightContent instead.

      Available in iOS 2.0 and later.

      Deprecated in iOS 7.0.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    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

    • None

      UIStatusBarAnimationNone

      No animation is applied to the status bar as it is shown or hidden.

      Available in iOS 3.2 and later.

    • Fade

      UIStatusBarAnimationFade

      The status bar fades in and out as it is shown or hidden, respectively.

      Available in iOS 3.2 and later.

    • Slide

      UIStatusBarAnimationSlide

      The status bar slides in or out as it is shown or hidden, respectively.

      Available in iOS 3.2 and later.

    Discussion

    Constants of the UIStatusBarAnimation type are arguments of the setStatusBarHidden:withAnimation: method.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    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

    • Active

      UIApplicationStateActive

      The app is running in the foreground and currently receiving events.

      Available in iOS 4.0 and later.

    • Inactive

      UIApplicationStateInactive

      The 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.

    • Background

      UIApplicationStateBackground

      The app is running in the background.

      Available in iOS 4.0 and later.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 4.0 and later.

  • Constants used when running in the background.

    Declaration

    Swift

    let UIBackgroundTaskInvalid: UIBackgroundTaskIdentifier let UIMinimumKeepAliveTimeout: NSTimeInterval

    Objective-C

    const UIBackgroundTaskIdentifier UIBackgroundTaskInvalid; const NSTimeInterval UIMinimumKeepAliveTimeout;

    Constants

    • UIBackgroundTaskInvalid

      UIBackgroundTaskInvalid

      An 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.

    • UIMinimumKeepAliveTimeout

      UIMinimumKeepAliveTimeout

      The 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

    • NewData

      UIBackgroundFetchResultNewData

      New data was successfully downloaded.

      Available in iOS 7.0 and later.

    • NoData

      UIBackgroundFetchResultNoData

      There was no new data to download.

      Available in iOS 7.0 and later.

    • Failed

      UIBackgroundFetchResultFailed

      An 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 UIKit

    Availability

    Available in iOS 7.0 and later.

  • Constants indicating fetch intervals for background downloads.

    Declaration

    Swift

    let UIApplicationBackgroundFetchIntervalMinimum: NSTimeInterval let UIApplicationBackgroundFetchIntervalNever: NSTimeInterval

    Objective-C

    const NSTimeInterval UIApplicationBackgroundFetchIntervalMinimum; const NSTimeInterval UIApplicationBackgroundFetchIntervalNever;

    Constants

    • UIApplicationBackgroundFetchIntervalMinimum

      UIApplicationBackgroundFetchIntervalMinimum

      The smallest fetch interval supported by the system.

      Available in iOS 7.0 and later.

    • UIApplicationBackgroundFetchIntervalNever

      UIApplicationBackgroundFetchIntervalNever

      A 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

    • Restricted

      UIBackgroundRefreshStatusRestricted

      Background 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.

    • Denied

      UIBackgroundRefreshStatusDenied

      The user explicitly disabled background behavior for this app or for the whole system.

      Available in iOS 7.0 and later.

    • Available

      UIBackgroundRefreshStatusAvailable

      Background updates are available for the app.

      Available in iOS 7.0 and later.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    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 } extension UIInterfaceOrientation { var isLandscape: Bool { get } var isPortrait: Bool { get } } extension UIInterfaceOrientation { var isLandscape: Bool { get } var isPortrait: Bool { get } }

    Objective-C

    typedef enum : NSInteger { UIInterfaceOrientationUnknown = UIDeviceOrientationUnknown, UIInterfaceOrientationPortrait = UIDeviceOrientationPortrait, UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown, UIInterfaceOrientationLandscapeLeft = UIDeviceOrientationLandscapeRight, UIInterfaceOrientationLandscapeRight = UIDeviceOrientationLandscapeLeft } UIInterfaceOrientation;

    Constants

    • Unknown

      UIInterfaceOrientationUnknown

      The orientation of the device cannot be determined.

      Available in iOS 8.0 and later.

    • Portrait

      UIInterfaceOrientationPortrait

      The device is in portrait mode, with the device held upright and the home button on the bottom.

      Available in iOS 2.0 and later.

    • PortraitUpsideDown

      UIInterfaceOrientationPortraitUpsideDown

      The 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.

    • LandscapeLeft

      UIInterfaceOrientationLandscapeLeft

      The 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.

    • LandscapeRight

      UIInterfaceOrientationLandscapeRight

      The 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

    You use these constants in the statusBarOrientation property and the setStatusBarOrientation:animated: method. Notice that UIDeviceOrientationLandscapeRightis assigned to UIInterfaceOrientationLandscapeLeft and UIDeviceOrientationLandscapeLeft is assigned to UIInterfaceOrientationLandscapeRight; 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 UIKit

    Availability

    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 : RawOptionSetType { init(_ rawValue: UInt) init(rawValue rawValue: 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

    • Portrait

      UIInterfaceOrientationMaskPortrait

      The view controller supports a portrait interface orientation.

      Available in iOS 6.0 and later.

    • LandscapeLeft

      UIInterfaceOrientationMaskLandscapeLeft

      The view controller supports a landscape-left interface orientation.

      Available in iOS 6.0 and later.

    • LandscapeRight

      UIInterfaceOrientationMaskLandscapeRight

      The view controller supports a landscape-right interface orientation.

      Available in iOS 6.0 and later.

    • PortraitUpsideDown

      UIInterfaceOrientationMaskPortraitUpsideDown

      The view controller supports an upside-down portrait interface orientation.

      Available in iOS 6.0 and later.

    • Landscape

      UIInterfaceOrientationMaskLandscape

      The view controller supports both landscape-left and landscape-right interface orientation.

      Available in iOS 6.0 and later.

    • All

      UIInterfaceOrientationMaskAll

      The view controller supports all interface orientations.

      Available in iOS 6.0 and later.

    • AllButUpsideDown

      UIInterfaceOrientationMaskAllButUpsideDown

      The view controller supports all but the upside-down portrait interface orientation.

      Available in iOS 6.0 and later.

    Discussion

    You return 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 UIKit

    Availability

    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

    • LeftToRight

      UIUserInterfaceLayoutDirectionLeftToRight

      The layout direction is left to right.

      Available in iOS 5.0 and later.

    • RightToLeft

      UIUserInterfaceLayoutDirectionRightToLeft

      The 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 userInterfaceLayoutDirection property. It indicates the directionality of the language in the user interface of the app.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 5.0 and later.

  • Constant used to open the app’s settings.

    Declaration

    Swift

    let UIApplicationOpenSettingsURLString: String

    Objective-C

    NSString *const UIApplicationOpenSettingsURLString;

    Constants

    • UIApplicationOpenSettingsURLString

      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.

      Available in iOS 8.0 and later.

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

    Declaration

    Swift

    let UIApplicationStatusBarOrientationUserInfoKey: String let UIApplicationStatusBarFrameUserInfoKey: String

    Objective-C

    NSString *const UIApplicationStatusBarOrientationUserInfoKey; NSString *const UIApplicationStatusBarFrameUserInfoKey;

    Constants

  • 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: String

    Objective-C

    NSString *const UIContentSizeCategoryExtraSmall; NSString *const UIContentSizeCategorySmall; NSString *const UIContentSizeCategoryMedium; NSString *const UIContentSizeCategoryLarge; NSString *const UIContentSizeCategoryExtraLarge; NSString *const UIContentSizeCategoryExtraExtraLarge; NSString *const UIContentSizeCategoryExtraExtraExtraLarge;

    Constants

    • UIContentSizeCategoryExtraSmall

      UIContentSizeCategoryExtraSmall

      An extra small font.

      Available in iOS 7.0 and later.

    • UIContentSizeCategorySmall

      UIContentSizeCategorySmall

      A small font.

      Available in iOS 7.0 and later.

    • UIContentSizeCategoryMedium

      UIContentSizeCategoryMedium

      A medium-sized font.

      Available in iOS 7.0 and later.

    • UIContentSizeCategoryLarge

      UIContentSizeCategoryLarge

      A large font.

      Available in iOS 7.0 and later.

    • UIContentSizeCategoryExtraLarge

      UIContentSizeCategoryExtraLarge

      An extra large font.

      Available in iOS 7.0 and later.

    • UIContentSizeCategoryExtraExtraLarge

      UIContentSizeCategoryExtraExtraLarge

      An increasingly large font.

      Available in iOS 7.0 and later.

    • UIContentSizeCategoryExtraExtraExtraLarge

      UIContentSizeCategoryExtraExtraExtraLarge

      The 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: String

    Objective-C

    NSString *const UIContentSizeCategoryAccessibilityMedium; NSString *const UIContentSizeCategoryAccessibilityLarge; NSString *const UIContentSizeCategoryAccessibilityExtraLarge; NSString *const UIContentSizeCategoryAccessibilityExtraExtraLarge; NSString *const UIContentSizeCategoryAccessibilityExtraExtraExtraLarge;

    Constants

    • UIContentSizeCategoryAccessibilityMedium

      UIContentSizeCategoryAccessibilityMedium

      A medium font size reflecting the current accessibility settings.

      Available in iOS 7.0 and later.

    • UIContentSizeCategoryAccessibilityLarge

      UIContentSizeCategoryAccessibilityLarge

      A large font size reflecting the current accessibility settings.

      Available in iOS 7.0 and later.

    • UIContentSizeCategoryAccessibilityExtraLarge

      UIContentSizeCategoryAccessibilityExtraLarge

      A medium font size reflecting the current accessibility settings.

      Available in iOS 7.0 and later.

    • UIContentSizeCategoryAccessibilityExtraExtraLarge

      UIContentSizeCategoryAccessibilityExtraExtraLarge

      A medium font size reflecting the current accessibility settings.

      Available in iOS 7.0 and later.

    • UIContentSizeCategoryAccessibilityExtraExtraExtraLarge

      UIContentSizeCategoryAccessibilityExtraExtraExtraLarge

      A 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: String

    Objective-C

    NSString *const UIContentSizeCategoryNewValueKey;

    Constants

    • UIContentSizeCategoryNewValueKey

      UIContentSizeCategoryNewValueKey

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

      Available in iOS 7.0 and later.

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

    Declaration

    Swift

    let UIApplicationKeyboardExtensionPointIdentifier: String

    Objective-C

    NSString *const UIApplicationKeyboardExtensionPointIdentifier;

    Constants

    • UIApplicationKeyboardExtensionPointIdentifier

      UIApplicationKeyboardExtensionPointIdentifier

      The 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: String

    Objective-C

    UIKIT_EXTERN NSString *UITrackingRunLoopMode;

    Constants

    • UITrackingRunLoopMode

      UITrackingRunLoopMode

      The mode set while tracking in controls takes place. You can use this mode to add timers that fire during tracking.

      Available in iOS 2.0 and later.

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

    Declaration

    Swift

    let UIApplicationInvalidInterfaceOrientationException: String

    Objective-C

    NSString *const UIApplicationInvalidInterfaceOrientationException;

    Constants

    • UIApplicationInvalidInterfaceOrientationException

      UIApplicationInvalidInterfaceOrientationException

      This exception is thrown if a view controller or the app returns 0 instead of a valid set of supported interface orientation values. It is also thrown if the orientation returned by a view controller’s preferredInterfaceOrientationForPresentation method does not match one of the view controller’s supported orientations.

      Available in iOS 6.0 and later.