Class: UIApplication

Inherits:
UIResponder show all

Overview

The UIApplication class provides a centralized point of control and coordination for applications running on iOS.

Instance Attribute Summary (collapse)

Attributes inherited from UIResponder

#inputAccessoryView, #inputView, #undoManager

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from UIResponder

#becomeFirstResponder, #canBecomeFirstResponder, #canPerformAction:withSender:, #canResignFirstResponder, #isFirstResponder, #motionBegan:withEvent:, #motionCancelled:withEvent:, #motionEnded:withEvent:, #nextResponder, #reloadInputViews, #remoteControlReceivedWithEvent:, #resignFirstResponder, #touchesBegan:withEvent:, #touchesCancelled:withEvent:, #touchesEnded:withEvent:, #touchesMoved:withEvent:

Methods inherited from NSObject

#!, #!=, #!~, #, #==, #===, #=~, #Rational, #__callee__, #__method__, #__send__, #__type__, `, alloc, allocWithZone:, #autoContentAccessingProxy, autoload, autoload?, autorelease_pool, #awakeAfterUsingCoder:, binding, block_given?, caller, cancelPreviousPerformRequestsWithTarget:, cancelPreviousPerformRequestsWithTarget:selector:object:, catch, class, classFallbacksForKeyedArchiver, #classForCoder, #classForKeyedArchiver, classForKeyedUnarchiver, #clone, conformsToProtocol:, #copy, copyWithZone:, #dealloc, #define_singleton_method, description, display, #doesNotRecognizeSelector:, #dup, #enum_for, #eql?, #equal?, #extend, fail, #finalize, format, #forwardInvocation:, #forwardingTargetForSelector:, framework, #freeze, #frozen?, getpass, gets, global_variables, #init, initialize, #initialize_clone, #initialize_copy, #initialize_dup, #inspect, instanceMethodForSelector:, instanceMethodSignatureForSelector:, #instance_eval, #instance_exec, #instance_of?, #instance_variable_defined?, #instance_variable_get, #instance_variable_set, #instance_variables, instancesRespondToSelector:, isSubclassOfClass:, #is_a?, iterator?, #kind_of?, lambda, load, load_bridge_support_file, load_plist, local_variables, loop, #method, #methodForSelector:, #methodSignatureForSelector:, #methods, #mutableCopy, mutableCopyWithZone:, new, #nil?, open, p, #performSelector:onThread:withObject:waitUntilDone:, #performSelector:onThread:withObject:waitUntilDone:modes:, #performSelector:withObject:afterDelay:, #performSelector:withObject:afterDelay:inModes:, #performSelectorInBackground:withObject:, #performSelectorOnMainThread:withObject:waitUntilDone:, #performSelectorOnMainThread:withObject:waitUntilDone:modes:, print, printf, #private_methods, proc, #protected_methods, #public_method, #public_methods, #public_send, putc, puts, raise, rand, readline, readlines, #replacementObjectForCoder:, #replacementObjectForKeyedArchiver:, require, resolveClassMethod:, resolveInstanceMethod:, #respond_to?, #respond_to_missing?, select, #send, setVersion:, #singleton_methods, sprintf, srand, superclass, #taint, #tainted?, #tap, test, throw, #to_plist, #to_s, trace_var, trap, #trust, #untaint, untrace_var, #untrust, #untrusted?, version

Constructor Details

This class inherits a constructor from NSObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class NSObject

Instance Attribute Details

- (Integer) applicationIconBadgeNumber

The number currently set as the badge of the application icon in Springboard. Set to 0 (zero) to hide the badge number. The default is 0.

Returns:

- (UIApplicationState) applicationState (readonly)

The runtime state of the application. (read-only) An application may be active, inactive, or running in the background. You can use the value in this property to determine which of these states the application is currently in.

Returns:

- (Boolean) applicationSupportsShakeToEdit

A Boolean value that determines whether shaking the device displays the undo-redo user interface. 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.

Returns:

  • (Boolean)

- (NSTimeInterval) backgroundTimeRemaining (readonly)

The amount of time the application has to run in the background. (read-only) This property contains the amount of time the application has to run in the background before it may be forcibly killed by the system. While the application is running in the foreground, the value in this property remains suitably large. If the application 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 application has left to run.

Returns:

  • (NSTimeInterval)

- (Object) delegate

The delegate of the application object. The delegate must adopt the UIApplicationDelegate formal protocol. UIApplication assigns and does not retain the delegate.

Returns:

- (Boolean) idleTimerDisabled

A Boolean value that controls whether the idle timer is disabled for the application. 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.

Returns:

  • (Boolean)

- (UIWindow) keyWindow (readonly)

The application's key window. (read-only) This property holds the UIWindow object in the windows array that is most recently sent the makeKeyAndVisible message.

Returns:

- (Boolean) networkActivityIndicatorVisible

A Boolean value that turns an indicator of network activity on or off. 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.

Returns:

  • (Boolean)

- (Boolean) protectedDataAvailable (readonly)

A Boolean value indicating whether content protection is active. (read-only) The value of this property is NO if content protection is enabled and the device is currently locked. The value of this property is set to YES if the device is unlocked or if content protection is not enabled.When the value of this property is NO, files that were assigned the NSFileProtectionComplete protection key cannot be read or written by your application. The user must unlock the device before your application can access them.

Returns:

  • (Boolean)

- (Array) scheduledLocalNotifications

All currently scheduled local notifications. This property holds an array of UILocalNotification instances representing the current scheduled local notifications. You can set or reset the local notifications in the array as well as access them.This method may be faster than using scheduleLocalNotification: when scheduling a large number of notifications.Note: Prior to iOS 4.2, this property was a read-only method. A setter method has been added and the method has been converted to a read-write property. When you set this property, UILocalNotification replaces all existing notifications by calling cancelLocalNotification: and then calling scheduleLocalNotification: for each new notification.

Returns:

- (CGRect) statusBarFrame (readonly)

The frame rectangle defining the area of the status bar. (read-only) The value of this property is CGRectZero if the status bar is hidden.

Returns:

- (Boolean) statusBarHidden

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

Returns:

  • (Boolean)

- (UIInterfaceOrientation) statusBarOrientation

The current orientation of the application's status bar. 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 views, see View Controller Programming Guide for iOS.

- (NSTimeInterval) statusBarOrientationAnimationDuration (readonly)

The animation duration in seconds for the status bar during a 90 degree orientation change. (read-only) You should double the value of this property for a 180 degree orientation change in the status bar.

Returns:

  • (NSTimeInterval)

- (UIStatusBarStyle) statusBarStyle

The current style of the status bar. 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.

Returns:

- (UIUserInterfaceLayoutDirection) userInterfaceLayoutDirection (readonly)

Returns the layout direction of the user interface. (read-only) This method specifies the general user interface layout flow direction. See “UIUserInterfaceLayoutDirection” for a description of the constants returned by this property.

- (Array) windows (readonly)

The application's visible and hidden windows. (read-only) This property returns an array of the application's visible and hidden windows. The windows are ordered back to front.

Returns:

Class Method Details

+ (UIApplication) sharedApplication

Returns the singleton application instance.

Returns:

  • (UIApplication)

    The application instance is created in the UIApplicationMain function.

Instance Method Details

- (UIBackgroundTaskIdentifier) beginBackgroundTaskWithExpirationHandler(handler)

Marks the beginning of a new long-running background task. This method lets your application 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 application’s user experience. For example, your application 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 application running after it moves to the background. Each call to this method must be balanced by a matching call to the endBackgroundTask: method. Applications 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 application. 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 application’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.This method can be safely called on a non-main thread.

Parameters:

  • handler

    A handler to be called shortly before the application’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 application. The handler is called synchronously on the main thread, thus blocking the application’s suspension momentarily while the application is notified.

Returns:

  • (UIBackgroundTaskIdentifier)

    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.

- (Object) beginIgnoringInteractionEvents

Tells the receiver to suspend the handling of touch-related events. You typically call this method before starting an animation or transition. Calls are nested with the endIgnoringInteractionEvents method.

Returns:

- (Object) beginReceivingRemoteControlEvents

Tells the application to begin receiving remote-control events. Remote-control events originate as commands issued by headsets and external accessories that are intended to control multimedia presented by an application. To stop the reception of remote-control events, you must call endReceivingRemoteControlEvents.

Returns:

- (Object) cancelAllLocalNotifications

Cancels the delivery of all scheduled local notifications.

Returns:

- (Object) cancelLocalNotification(notification)

Cancels the delivery of the specified scheduled local notification. Calling this method also programmatically dismisses the notification if it is currently displaying an alert.

Parameters:

  • notification (UILocalNotification)

    The local notification to cancel.

Returns:

- (Boolean) canOpenURL(url)

Returns whether an application can open a given URL resource. 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.

Parameters:

  • url (NSURL)

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

Returns:

  • (Boolean)

    NO if no application is available that will accept the URL; otherwise, returns YES.

- (Object) clearKeepAliveTimeout

Removes a previously installed periodic handler block. If your VoIP application no longer needs to be woken up at periodic intervals, you can use this method to remove any previously installed handler.

Returns:

- (Object) completeStateRestoration

Tells the app that your code has finished any asynchronous state restoration. UIKit restores your application’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.

Returns:

- (UIRemoteNotificationType) enabledRemoteNotificationTypes

Returns the types of notifications the application accepts. 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. iOS 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.

Returns:

- (Object) endBackgroundTask(identifier)

Marks the end of a specific long-running background task. 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 application. This method can be safely called on a non-main thread.

Parameters:

  • identifier (UIBackgroundTaskIdentifier)

    An identifier returned by the beginBackgroundTaskWithExpirationHandler: method.

Returns:

- (Object) endIgnoringInteractionEvents

Tells the receiver to resume the handling of touch-related events. 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.

Returns:

- (Object) endReceivingRemoteControlEvents

Tells the application to stop receiving remote-control events. Remote-control events originate as commands issued by headsets and external accessories that are intended to control multimedia presented by an application.

Returns:

- (Object) extendStateRestoration

Tells the app that your code is restoring state asynchronously. UIKit restores your application’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.

Returns:

- (Boolean) isIgnoringInteractionEvents

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

Returns:

  • (Boolean)

    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.

- (Boolean) openURL(url)

Opens the resource at the specified URL. 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.

Parameters:

  • url (NSURL)

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

Returns:

  • (Boolean)

    YES if the resource located by the URL was successfully opened; otherwise NO.

- (Object) presentLocalNotificationNow(notification)

Presents a local notification immediately.

Parameters:

  • notification (UILocalNotification)

    A local notification that the operating system presents for the application immediately, regardless of the value of the notification’s fireDate property. Applications running in the background state can immediately present local notifications when there are incoming chats, messages, or updates. Because the operating system copies notification, you may release it once you have scheduled it.

Returns:

- (Object) registerForRemoteNotificationTypes(types)

Register to receive notifications of the specified types from a provider via Apple Push Service. 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. 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 application’s current notification types are, call the enabledRemoteNotificationTypes method.

Parameters:

Returns:

- (Object) scheduleLocalNotification(notification)

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

Parameters:

  • notification (UILocalNotification)

    A local notification that the operating system delivers for the application at the date and time specified in the fireDate property of notification. Because the operating system copies notification, you may release it once you have scheduled it.

Returns:

- (Boolean) sendAction(action, to:target, from:sender, forEvent:event)

Sends an action message identified by selector to a specified target. 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

Parameters:

  • action (Symbol)

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

  • target (Object)

    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.

  • sender (Object)

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

  • event (UIEvent)

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

Returns:

  • (Boolean)

    YES if a responder object handled the action message, NO if no object in the responder chain handled the message.

- (Object) sendEvent(event)

Dispatches an event to the appropriate responder objects in the application. Subclasses may override this method to intercept incoming events for inspection and special dispatching. iOS calls this method for public events only.

Parameters:

  • event (UIEvent)

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

Returns:

- (Boolean) setKeepAliveTimeout(timeout, handler:keepAliveHandler)

Configures a periodic handler for VoIP applications. A voice-over-IP (VoIP) application can use this method to install a handler whose job is to maintain the application’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 application is suspended. Timeout values and handlers are not persisted between application launches. Therefore, if your application is terminated for any reason, you must reinstall the handler during the next launch cycle. For calls to this method to succeed, the application 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.

Parameters:

  • timeout

    The maximum interval (measured in seconds) at which your application 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.

Returns:

  • (Boolean)

    YES if the handler was installed or NO if it was not.

- (Object) setNewsstandIconImage(image)

Sets the icon of a Newsstand application to an image depicting the current issue of a publication. The Newsstand application icon is typically downloaded from the application’s server for each issue.

Parameters:

  • image (UIImage)

    An image to use as the icon of a Newsstand application. Pass nil to clear the currently set image and revert to the icon stored in the application bundle.

Returns:

- (Object) setStatusBarHidden(hidden, withAnimation:animation)

Hides or shows the status bar, optionally animating the transition. See the descriptions of the constants of the UIStatusBarAnimation type for more information.

Parameters:

  • hidden (Boolean)

    YES to hide the status bar, NO to show the status bar.

  • animation (UIStatusBarAnimation)

    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.

Returns:

- (Object) setStatusBarOrientation(interfaceOrientation, animated:animated)

Sets the application's status bar to the specified orientation, optionally animating the transition. 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.

Parameters:

  • interfaceOrientation (UIInterfaceOrientation)

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

  • animated (Boolean)

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

Returns:

- (Object) setStatusBarStyle(statusBarStyle, animated:animated)

Sets the style of the status bar, optionally animating the transition to the new style. The animation slides the status bar out toward the top of the interface.

Parameters:

  • statusBarStyle (UIStatusBarStyle)

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

  • animated (Boolean)

    YES if the transition to the new style should be animated; otherwise NO .

Returns:

- (Integer) supportedInterfaceOrientationsForWindow(window)

Returns the default set of interface orientations to use for the view controllers in the specified window. 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 UIInterfaceOrientation 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.

Parameters:

  • window (UIWindow)

    The window whose default interface orientations you want to retrieve.

Returns:

  • (Integer)

    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.

- (Object) unregisterForRemoteNotifications

Unregister for notifications received from Apple Push Service. 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.

Returns: