| Inherits from | |
| Conforms to | |
| Framework | /System/Library/Frameworks/UIKit.framework |
| Availability | Available in iPhone OS 2.0 and later. |
| Declared in | UIApplication.h |
| Related sample code |
The UIApplication class provides a centralized point of control and coordination for applications running on iPhone OS.
Every application must have exactly one instance of UIApplication (or a subclass of UIApplication ). When an application is launched, the UIApplicationMain function is called; among its other tasks, this function create a singleton UIApplication object. Thereafter you can 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 application, so through those it can retrieve any of the applicationâs UIView objects. The application object is typically assigned a delegate, an object that the application informs of significant runtime eventsâfor example, application launch, low-memory warnings, and application terminationâgiving it an opportunity to respond appropriately.
Applications can cooperatively handle a resource such as an email or an image file through the openURL: method. For example, an application opening an email URL with this method may cause the mail client to launch and display the message.
For iPhone OS 3.0, UIApplication has added methods for remote-notification registration, for triggering of the undo-redo UI (applicationSupportsShakeToEdit), and for determining whether any installed application can open a URL (canOpenURL:).
UIApplication defines a delegate that must adopt the UIApplicationDelegate protocol implement one or more of the methods.
The programmatic interfaces of UIApplication and UIApplicationDelegate also allow you to manage behavior that is specific to the device. You can control application response to changes in interface orientation, temporarily suspend incoming user events, and turn proximity sensing (of the userâs face) off and on again.
You might decide to subclass UIApplication to override sendEvent: or sendAction:to:from:forEvent: to implement custom event and action dispatching. However, there is rarely a valid need to extend this class; the application delegate (UIApplicationDelegate is sufficient for most occasions. If you do subclass UIApplication, be very sure of what you are trying to accomplish with the subclass.
– sendEvent:
– sendAction:to:from:forEvent:
– beginIgnoringInteractionEvents
– endIgnoringInteractionEvents
– isIgnoringInteractionEvents
applicationSupportsShakeToEdit property
proximitySensingEnabled property
– registerForRemoteNotificationTypes:
– unregisterForRemoteNotifications
– enabledRemoteNotificationTypes
idleTimerDisabled property
– setStatusBarOrientation:animated:
statusBarOrientation property
statusBarOrientationAnimationDuration property
– setStatusBarHidden:animated:
statusBarHidden property
– setStatusBarStyle:animated:
statusBarStyle property
statusBarFrame property
networkActivityIndicatorVisible property
applicationIconBadgeNumber property
delegate property
For more about Objective-C properties, see “Properties” in The Objective-C Programming Language.
The number currently set as the badge of the application icon in Springboard.
@property(nonatomic) NSInteger applicationIconBadgeNumber
Set to 0 (zero) to hide the badge number. The default is 0.
UIApplication.hA Boolean value that determines whether shaking the device displays the undo-redo user interface.
@property(nonatomic) BOOL applicationSupportsShakeToEdit
The default value is YES. Set the property to NO if you don’t want your application to display the Undo and Redo buttons when users shake the device.
UIApplication.hThe delegate of the application object.
@property(nonatomic, assign) id<UIApplicationDelegate> delegate
The delegate must adopt the UIApplicationDelegate formal protocol. UIApplication assigns and does not retain the delegate.
UIApplication.hA Boolean value that controls whether the idle timer is disabled for the application.
@property(nonatomic, getter=isIdleTimerDisabled) BOOL idleTimerDisabled
The default value of this property is NO. When most applications 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, applications that don't have user input except for the accelerometerâgames, for instanceâcan, by setting this property to YES, disable the âidle timerâ to avert system sleep.
Important: You should set this property only if necessary and should be sure to reset it to NO when the need no longer exists. Most applications should let the system turn off the screen when the idle timer elapses. This includes audio applications. With appropriate use of Audio Session Services, playback and recording proceed uninterrupted when the screen turns off. The only applications that should disable the idle timer are mapping applications, games, or similar programs with sporadic user interaction.
UIApplication.hThe applicationâs key window. (read-only)
@property(nonatomic, readonly) UIWindow *keyWindow
This property holds the UIWindow object in the windows array that is most recently sent the makeKeyAndVisible message.
UIApplication.hA Boolean value that turns an indicator of network activity on or off.
@property(nonatomic, getter=isNetworkActivityIndicatorVisible) BOOL networkActivityIndicatorVisible
Specify YES if the application should show network activity and NO if it should not. The default value is NO. A spinning indicator in the status bar shows network activity. The application may explicitly hide or show this indicator.
UIApplication.hA Boolean value that determines whether proximity sensing is enabled. (Deprecated. The properties proximityMonitoringEnabled and proximityState of the UIDevice class are the replacements.)
@property(nonatomic, getter=isProximitySensingEnabled) BOOL proximitySensingEnabled
YES if proximity sensing is enabled; otherwise NO. Enabling proximity sensing tells iPhone OS that it may need to blank the screen if the userâs face is near it. Proximity sensing is disabled by default.
UIApplication.hThe frame rectangle defining the area of the status bar. (read-only)
@property(nonatomic, readonly) CGRect statusBarFrame
The value of this property is CGRectZero if the status bar is hidden.
UIApplication.hA Boolean value that determines whether the status bar is hidden.
@property(nonatomic, getter=isStatusBarHidden) BOOL statusBarHidden
YES means the status bar is hidden; NO means itâs visible.
UIApplication.hThe current orientation of the applicationâs status bar.
@property(nonatomic) UIInterfaceOrientation statusBarOrientation
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 application 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 view, see the UIWindow class reference.
UIApplication.hThe animation duration in seconds for the status bar during a 90 degree orientation change. (read-only)
@property(nonatomic, readonly) NSTimeInterval statusBarOrientationAnimationDuration
You should double the value of this property for a 180 degree orientation change in the status bar.
UIApplication.hThe current style of the status bar.
@property(nonatomic) UIStatusBarStyle statusBarStyle
The value of the property is a UIStatusBarStyle constant that indicates the style of status. The default style is UIStatusBarStyleDefault. The animation slides the status bar out for the old orientation and slides it in for the new orientation.
UIApplication.hThe applicationâs visible windows. (read-only)
@property(nonatomic, readonly) NSArray *windows
This property is an array holding the application's visible windows; the windows are ordered back to front.
UIApplication.hReturns the singleton application instance.
+ (UIApplication *)sharedApplication
The application instance is created in the UIApplicationMain function.
UIApplication.hTells the receiver to suspend the handling of touch-related events.
- (void)beginIgnoringInteractionEvents
You typically call this method before starting an animation or transition. Calls are nested with the endIgnoringInteractionEvents method.
UIApplication.hReturns whether an application can open a given URL resource.
- (BOOL)canOpenURL:(NSURL *)url
A URL object that identifies a given resource. The URL’s scheme—possibly a custom scheme—identifies which application can handle the URL.
NO if no application is available that will accept the URL; otherwise, returns YES.
This method guarantees that that if openURL: is called, another application will be launched to handle it. It does not guarantee that the full URL is valid.
UIApplication.hReturns the types of notifications the application accepts.
- (UIRemoteNotificationType)enabledRemoteNotificationTypes
A bit mask whose values indicate the types of notifications the user has requested for the application. See UIRemoteNotificationType for valid bit-mask values.
The values in the returned bit mask indicate the types of notifications currently enabled for the application. These types are first set when the application 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 application. This method returns those initial or modified values. iPhone OS does not display or play notification types specified in the notification payload that are not one of the enabled types. For example, the application 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.
UIApplication.hTells the receiver to resume the handling of touch-related events.
- (void)endIgnoringInteractionEvents
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.
UIApplication.hReturns whether the receiver is ignoring events initiated by touches on the screen.
- (BOOL)isIgnoringInteractionEvents
YES if the receiver is ignoring interaction events; otherwise NO. The method returns YES if the nested beginIgnoringInteractionEvents and endIgnoringInteractionEvents calls are at least one level deep.
UIApplication.hOpens the resource at the specified URL.
- (BOOL)openURL:(NSURL *)url
An object representing a URL (Universal Resource Locator). UIKit supports the http:, https:, tel:, and mailto: schemes.
YES if the resource located by the URL was successfully opened; otherwise NO.
The URL can locate a resource in the same or other application. If the resource is another application, invoking this method may cause the calling application to quit so the other one can be launched.
You may call canOpenURL: before calling this one to verify that there is an application that can handle it.
– application:handleOpenURL: (UIApplicationDelegate)UIApplication.hRegister to receive notifications of the specified types from a provider via Apple Push Service.
- (void)registerForRemoteNotificationTypes:(UIRemoteNotificationType)types
A bit mask specifying the types of notifications the application accepts. See UIRemoteNotificationType for valid bit-mask values.
When you send this message, the device initiates the registration process with Apple Push Service. If it succeeds, the application 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 application delegate receives a device token, it should connect with its provider and pass it the token.
iPhone OS 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, iPhone OS does not display an alert even if one is specified in the notification payload. To find out what the application’s current notification types are, call the enabledRemoteNotificationTypes method.
UIApplication.hSends an action message identified by selector to a specified target.
- (BOOL)sendAction:(SEL)action to:(id)target from:(id)sender forEvent:(UIEvent *)event
A selector identifying an action method. See the discussion for information on the permitted selector forms.
The object to receive the action message. If target is nil, the application sends the message to the first responder, from whence it progresses up the responder chain until it is handled.
The object that is sending the action message. The default sender is the UIControl object that invokes this method.
A UIEvent object that encapsulates information about the event originating the action message.
YES if a responder object handled the action message, NO if no object in the responder chain handled the message.
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
UIApplication.hDispatches an event to the appropriate responder objects in the application.
- (void)sendEvent:(UIEvent *)event
A UIEvent object encapsulating the information about an event, including the touches involved.
Subclasses may override this method to intercept incoming events for inspection and special dispatching. iPhone OS calls this method for public events only.
UIApplication.hHides or shows the status bar, optionally animating the transition.
- (void)setStatusBarHidden:(BOOL)hidden animated:(BOOL)animated
YES if the status bar should be hidden, NO if it should be visible. The default value is NO.
YES if the transition to or from a hidden state should be animated, NO otherwise.
The animation fades the status bar out or in at the top of the interface, depending on the value of hidden.
UIApplication.hSets the applicationâs status bar to the specified orientation, optionally animating the transition.
- (void)setStatusBarOrientation:(UIInterfaceOrientation)interfaceOrientation animated:(BOOL)animated
A specific orientation of the status bar. See UIInterfaceOrientation for details. The default value is UIInterfaceOrientationPortrait.
YES if the transition to the new orientation should be animated; NO if it should be immediate, without animation.
Calling this method changes the value of the statusBarOrientation property and rotates the status bar, animating the transition if animated is YES . If your application 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.
UIApplication.hSets the style of the status bar, optionally animating the transition to the new style
- (void)setStatusBarStyle:(UIStatusBarStyle)statusBarStyle animated:(BOOL)animated
A constant that specifies a style for the status bar. See the descriptions of the constants in UIStatusBarStyle for details.
YES if the transition to the new style should be animated; otherwise NO .
The animation slides the status bar out toward the top of the interface.
UIApplication.hUnregister for notifications received from Apple Push Service.
- (void)unregisterForRemoteNotifications
You should call this method in rare circumstances only, such as when a new version of the application drops support for remote notifications. Users can temporarily prevent applications from receiving remote notifications through the Notifications section of the Settings application. Applications unregistered through this method can always re-register.
UIApplication.hThe orientation of the application's user interface.
typedef enum {
UIInterfaceOrientationPortrait = UIDeviceOrientationPortrait,
UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown,
UIInterfaceOrientationLandscapeLeft = UIDeviceOrientationLandscapeRight,
UIInterfaceOrientationLandscapeRight = UIDeviceOrientationLandscapeLeft
} UIInterfaceOrientation;
UIInterfaceOrientationPortraitThe device is in portrait mode, with the device held upright and the home button on the bottom.
Available in iPhone OS 2.0 and later.
Declared in UIApplication.h.
UIInterfaceOrientationPortraitUpsideDownThe device is in portrait mode but upside down, with the device held upright and the home button at the top.
Available in iPhone OS 2.0 and later.
Declared in UIApplication.h.
UIInterfaceOrientationLandscapeLeftThe device is in landscape mode, with the device held upright and the home button on the left side.
Available in iPhone OS 2.0 and later.
Declared in UIApplication.h.
UIInterfaceOrientationLandscapeRightThe device is in landscape mode, with the device held upright and the home button on the right side.
Available in iPhone OS 2.0 and later.
Declared in UIApplication.h.
You use these constants in the statusBarOrientation property and the setStatusBarOrientation:animated: method. Notice that UIDeviceOrientationLandscapeRight is 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.
UIApplication.hThe style of the device’s status bar.
typedef enum {
UIStatusBarStyleDefault,
UIStatusBarStyleBlackTranslucent,
UIStatusBarStyleBlackOpaque
} UIStatusBarStyle;
UIStatusBarStyleDefaultA gray style (the default).
Available in iPhone OS 2.0 and later.
Declared in UIApplication.h.
UIStatusBarStyleBlackTranslucentA transparent black style (specifically, black with an alpha of 0.5).
Available in iPhone OS 2.0 and later.
Declared in UIApplication.h.
UIStatusBarStyleBlackOpaqueAn opaque black style.
Available in iPhone OS 2.0 and later.
Declared in UIApplication.h.
UIApplication.hMode while tracking in controls is taking place.
UIKIT_EXTERN NSString *UITrackingRunLoopMode;
UITrackingRunLoopModeThe mode set while tracking in controls takes place. You can use this mode to add timers that fire during tracking.
Available in iPhone OS 2.0 and later.
Declared in UIApplication.h.
UIApplication.hKeys used to access values in the userInfo dictionary of some UIApplication-posted notifications and in the dictionary passed into application:didFinishLaunchingWithOptions: method declared in the UIApplicationDelegate protocol.
UIKIT_EXTERN NSString *const UIApplicationStatusBarOrientationUserInfoKey; UIKIT_EXTERN NSString *const UIApplicationWillChangeStatusBarFrameNotification; UIKIT_EXTERN NSString *const UIApplicationDidChangeStatusBarFrameNotification; UIKIT_EXTERN NSString *const UIApplicationStatusBarFrameUserInfoKey; UIKIT_EXTERN NSString *const UIApplicationLaunchOptionsURLKey; UIKIT_EXTERN NSString *const UIApplicationLaunchOptionsSourceApplicationKey; UIKIT_EXTERN NSString *const UIApplicationLaunchOptionsRemoteNotificationKey;
UIApplicationStatusBarOrientationUserInfoKeyAccesses an NSNumber object that encapsulates a UIInterfaceOrientation value indicating the current orientation (see UIInterfaceOrientation). This key is used with UIApplicationDidChangeStatusBarOrientationNotification and UIApplicationWillChangeStatusBarOrientationNotification notifications.
Available in iPhone OS 2.0 and later.
Declared in UIApplication.h.
UIApplicationStatusBarFrameUserInfoKeyAccesses an NSValue object that encapsulates a CGRect structure expressing the location and size of the new status bar frame. This key is used with UIApplicationDidChangeStatusBarFrameNotification and UIApplicationWillChangeStatusBarFrameNotification notifications.
Available in iPhone OS 2.0 and later.
Declared in UIApplication.h.
UIApplicationLaunchOptionsURLKeyYou use this key to access contents of the dictionary passed in the second parameter of the UIApplicationDelegate method application:didFinishLaunchingWithOptions:. It returns an NSURL object that another application specified in openURL:, which resulted in iPhone OS launching the application to handle the URL resource.
This key is also used to access the same value in the userInfo dictionary of the notification named UIApplicationDidFinishLaunchingNotification.
Available in iPhone OS 3.0 and later.
Declared in UIApplication.h.
UIApplicationLaunchOptionsSourceApplicationKeyYou use this key to access contents of the dictionary passed in the second parameter of the UIApplicationDelegate method application:didFinishLaunchingWithOptions:. It returns an NSString object that represents the bundle ID of the application that requested the launch by calling openURL:.
This key is also used to access the same value in the userInfo dictionary of the notification named UIApplicationDidFinishLaunchingNotification.
Available in iPhone OS 3.0 and later.
Declared in UIApplication.h.
UIApplicationLaunchOptionsRemoteNotificationKeyYou use this key to access contents of the dictionary passed in the second parameter of the UIApplicationDelegate method application:didFinishLaunchingWithOptions:. It returns a dictionary representing the payload of the remote notification.
See the description of application:didReceiveRemoteNotification: for further information. This key is also used to access the same value in the userInfo dictionary of the notification named UIApplicationDidFinishLaunchingNotification.
Available in iPhone OS 3.0 and later.
Declared in UIApplication.h.
UIApplication.hConstants indicating the types of notifications the application accepts.
typedef enum {
UIRemoteNotificationTypeNone = 0,
UIRemoteNotificationTypeBadge = 1 << 0,
UIRemoteNotificationTypeSound = 1 << 1,
UIRemoteNotificationTypeAlert = 1 << 2
} UIRemoteNotificationType;
UIRemoteNotificationTypeNoneThe application accepts no notifications.
Available in iPhone OS 3.0 and later.
Declared in UIApplication.h.
UIRemoteNotificationTypeBadgeThe application accepts notifications that badge the application icon.
Available in iPhone OS 3.0 and later.
Declared in UIApplication.h.
UIRemoteNotificationTypeSoundThe application accepts alert sounds as notifications.
Available in iPhone OS 3.0 and later.
Declared in UIApplication.h.
UIRemoteNotificationTypeAlertThe application accepts alert messages as notifications.
Available in iPhone OS 3.0 and later.
Declared in UIApplication.h.
One or more of the values in the UIRemoteNotificationType bit mask are passed to iPhone OS as the argument of the registerForRemoteNotificationTypes: method. Thereafter, iPhone OS filters notifications for the application based on these values. You can always get the current notification types by calling the enabledRemoteNotificationTypes method.
UIApplication.hAll UIApplication notifications are posted by the application instance returned by sharedApplication.
Posted when the application becomes active.
An application is active when it is receiving events. An active application 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.
UIApplication.hPosted when the frame of the status bar changes.
The userInfo dictionary contains an NSValue object that encapsulates a CGRect structure expressing the location and size of the new status bar frame. Use UIApplicationStatusBarFrameUserInfoKey to access this value.
UIApplication.hPosted immediately after the application finishes launching.
If the application was launched as a result of in remote notification targeted at it or because another application opened a URL resource claimed the posting application (the notification object), this notification contains a userInfo dictionary. You can access the contents of the dictionary using the UIApplicationLaunchOptionsURLKey and UIApplicationLaunchOptionsSourceApplicationKey constants (for URLs) or the UIApplicationLaunchOptionsRemoteNotificationKey constant (for remote notifications). If the notification was posted for a normal application launch, there is no userInfo dictionary.
UIApplication.hPosted when the application receives a warning from the operating system about low memory availability.
This notification does not contain a userInfo dictionary.
UIApplication.hPosted 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 userInfo dictionary.
UIApplication.hPosted when the application is about to change the orientation of its interface.
The userInfo dictionary contains an NSNumber that encapsulates a UIInterfaceOrientation value (see UIInterfaceOrientation). Use UIApplicationStatusBarOrientationUserInfoKey to access this value.
UIApplication.hPosted when the orientation of the applicationâs user interface changes.
The userInfo dictionary contains an NSNumber object that encapsulates a UIInterfaceOrientation value (see UIInterfaceOrientation). Use UIApplicationStatusBarOrientationUserInfoKey to access this value
UIApplication.hPosted when the application is about to change the frame of the status bar.
The userInfo dictionary contains an NSValue object that encapsulates a CGRect structure expressing the location and size of the new status bar frame. Use UIApplicationStatusBarFrameUserInfoKey to access this value.
UIApplication.hPosted when the application is no longer active and loses focus.
An application is active when it is receiving events. An active application 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.
UIApplication.hPosted when the application is about to terminate.
This notification does not contain a userInfo dictionary.
UIApplication.hLast updated: 2009-11-17