iOS Developer Library — Pre-Release

Developer

UIKit Framework Reference UIApplicationDelegate Protocol Reference

Options
Deployment Target:

On This Page
Language:

UIApplicationDelegate

Inheritance


Not Applicable

Conforms To


Import Statement


Swift

import UIKit

Objective-C

@import UIKit;

Availability


Available in iOS 2.0 and later.

The UIApplicationDelegate protocol defines methods that are called by the singleton UIApplication object in response to important events in the lifetime of your app. The app delegate works alongside the app object to ensure your app interacts properly with the system and with other apps. Specifically, the methods of the app delegate give you a chance to respond to important changes. For example, you use the methods of the app delegate to respond to state transitions, such as when your app moves from foreground to background execution, and to respond to incoming notifications. In many cases, the methods of the app delegate are the only way to receive these important notifications.

Xcode provides an app delegate class for every new project, so you do not need to define one yourself initially. When your app launches, UIKit automatically creates an instance of the app delegate class provided by Xcode and uses it to execute the first bits of custom code in your app. All you have to do is take the class that Xcode provides and add your custom code.

The app delegate is effectively the root object of your app. Like the UIApplication object itself, the app delegate is a singleton object and is always present at runtime. Although the UIApplication object does most of the underlying work to manage the app, you decide your app’s overall behavior by providing appropriate implementations of the app delegate’s methods. Although most methods of this protocol are optional, you should implement most or all of them.

The app delegate performs several crucial roles:

  • It contains your app’s startup code.

  • It responds to key changes in the state of your app. Specifically, it responds to both temporary interruptions and to changes in the execution state of your app, such as when your app transitions from the foreground to the background.

  • It responds to notifications originating from outside the app, such as remote notifications (also known as push notifications), low-memory warnings, download completion notifications, and more.

  • It determines whether state preservation and restoration should occur and assists in the preservation and restoration process as needed.

  • It responds to events that target the app itself and are not specific to your app’s views or view controllers.

  • You can use it to store your app’s central data objects or any content that does not have an owning view controller.

For more information about the role of the app delegate and how it fits into the app architecture, see App Programming Guide for iOS. For more information about the UIApplication singleton class, see UIApplication Class Reference.

Starting Up Your App

Launch time is an important point in an app’s life cycle. At launch time, the app delegate is responsible for executing any custom code required to initialize your app. For example, the app delegate typically creates the app’s initial data structures, registers for any required services, and tweaks the app’s initial user interface based on any available data.

Some additional tasks that the app delegate performs at launch time include the following:

  • Look at the launch options dictionary to determine why your app was launched. The application:willFinishLaunchingWithOptions: and application:didFinishLaunchingWithOptions: methods provide a dictionary with keys indicating the reason that your app was launched.

  • Determine whether state restoration should proceed. If the app previously saved the state of its view controllers, restoration of those view controllers to their previous state proceeds only if the app delegate’s application:shouldRestoreApplicationState: method returns YEStrue.

  • Register for any remote notifications your app supports. In order to receive remote notifications (also known as push notifications), an app must register with the remote notification service by calling the registerForRemoteNotificationTypes: method of the UIApplication object. Usually, you perform this task at launch time.

  • Open a URL that was sent to your app. If there is a URL to open, the system calls the application:openURL:sourceApplication:annotation: method of your app delegate. You also can tell if there is a URL to open by looking in the launch options dictionary for the UIApplicationLaunchOptionsURLKey key. You must declare the types of URLs your app supports by adding the CFBundleURLTypes key to your app’s Info.plist file. For more information about registering and handling URLs, see App Programming Guide for iOS.

  • Provide the root window object for your app. Technically, the app delegate provided by Xcode already implements the window property, so you do not have to do anything special here unless you want to customize your app’s window.

The options dictionary passed to the application:willFinishLaunchingWithOptions: and application:didFinishLaunchingWithOptions: methods is an important source of launch-time information for your app. The keys in that dictionary tell you the reason your app was launched and give you a chance to adjust your launch procedures accordingly. For example, if your app was launched because of an incoming remote notification, you might want to reconfigure your user interface to display data related to that notification. For a list of possible reasons why your app might be launched, see Launch Options Keys.

Managing State Transitions

One of the main jobs of the app delegate is to respond to state transitions reported by the system. For every state change that occurs, the system calls the appropriate methods of the app delegate. Each state has different rules that govern how the app should is expected to behave and the app delegate methods must adjust the behavior of the app accordingly. Table 1 lists the possible states of an app and the high-level expectations. Figure 1 shows how an app moves from one state to another.

Table 1App states

State

Description

Not running

The app has not been launched or was terminated, either by the user or the system.

Inactive

The app is running in the foreground but is not receiving events. (It may be executing other code though.) An app usually stays in this state only briefly as it transitions to a different state.

Upon entering this state, the app should put itself into a quiescent state with the expectation of moving to the background or active state shortly.

Active

The app is running in the foreground and receiving events. This is the normal mode for foreground apps.

An app in the active state has no special restrictions placed on it. It is the foreground app and should be responsive to the user.

Background

The app is executing code but is not visible onscreen. When the user quits an app, the system moves the app to the background state briefly before suspending it. At other times, the system may launch the app into the background (or wake up a suspended app) and give it time to handle specific tasks. For example, the system may wake up an app so that it can process background downloads, certain types of location events, remote notifications, and other types of events.

An app in the background state should do as little work as possible. Apps that request time to process specific types of events should process those events and return control back to the system as quickly as possible.

Suspended

The app is in memory but is not executing code. The system suspends apps that are in the background and do not have any pending tasks to complete. The system may purge suspended apps at any time without waking them up to make room for other apps.

Figure 1State changes in an iOS app image: ../Art/high_level_flow_2x.png

The following methods are called when state transitions occur. For information about what to do in response to each transition, see the method descriptions:

The specific tasks you perform during a given state transition are dependent upon your app and its capabilities. For tips and guidance about what to do during state transitions, see App Programming Guide for iOS.

Responding to Notifications and Events

The system sends many different notifications and events to the app delegate, letting the app delegate decide how best to respond to the incoming information and update the app. Most of these notifications correspond to app-level behaviors that might require you to update your app’s data or user interface or respond to a changed condition of the system. The way you handle these notifications depends on the architecture of your app. In many cases, the app delegate might not do anything more than notify other objects (such as your app’s view controllers) that they need to update themselves, but in some cases the app delegate might do the work itself.

  • Tells the delegate that the launch process has begun but that state restoration has not yet occurred.

    Declaration

    Swift

    optional func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool

    Objective-C

    - (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions

    Parameters

    application

    The singleton app object.

    launchOptions

    A dictionary indicating the reason the app was launched (if any). The contents of this dictionary may be empty in situations where the user launched the app directly. For information about the possible keys in this dictionary and how to handle them, see Launch Options Keys.

    Return Value

    NOfalse if the app cannot handle the URL resource or continue a user activity, otherwise return YEStrue. The return value is ignored if the app is launched as a result of a remote notification.

    Discussion

    Use this method (and the corresponding application:didFinishLaunchingWithOptions: method) to initialize your app and prepare it to run. This method is called after your app has been launched and its main storyboard or nib file has been loaded, but before your app’s state has been restored. At the time this method is called, your app is in the inactive state.

    If your app was launched by the system for a specific reason, the launchOptions dictionary contains data indicating the reason for the launch. For some launch reasons, the system may call additional methods of your app delegate. For example, if your app was launched to open a URL, the system calls the application:openURL:sourceApplication:annotation: method after your app finishes initializing itself. The presence of the launch keys gives you the opportunity to plan for that behavior. In the case of a URL to open, you might want to prevent state restoration if the URL represents a document that the user wanted to open.

    When asked to open a URL, the return result from this method is combined with the return result from the application:didFinishLaunchingWithOptions: method to determine if a URL should be handled. If either method returns NOfalse, the system does not call the application:openURL:sourceApplication:annotation: method. If you do not implement one of the methods, only the return value of the implemented method is considered.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 6.0 and later.

  • Tells the delegate that the launch process is almost done and the app is almost ready to run.

    Declaration

    Swift

    optional func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool

    Objective-C

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

    Parameters

    application

    The singleton app object.

    launchOptions

    A dictionary indicating the reason the app was launched (if any). The contents of this dictionary may be empty in situations where the user launched the app directly. For information about the possible keys in this dictionary and how to handle them, see Launch Options Keys.

    Return Value

    NOfalse if the app cannot handle the URL resource or continue a user activity, otherwise return YEStrue. The return value is ignored if the app is launched as a result of a remote notification.

    Discussion

    Use this method (and the corresponding application:willFinishLaunchingWithOptions: method) to complete your app’s initialization and make any final tweaks. This method is called after state restoration has occurred but before your app’s window and other UI have been presented. At some point after this method returns, the system calls another of your app delegate’s methods to move the app to the active (foreground) state or the background state.

    This method represents your last chance to process any keys in the launchOptions dictionary. If you did not evaluate the keys in your application:willFinishLaunchingWithOptions: method, you should look at them in this method and provide an appropriate response.

    Objects that are not the app delegate can access the same launchOptions dictionary values by observing the notification named UIApplicationDidFinishLaunchingNotification and accessing the notification’s userInfo dictionary. That notification is sent shortly after this method returns.

    The return result from this method is combined with the return result from the application:willFinishLaunchingWithOptions: method to determine if a URL should be handled. If either method returns NOfalse, the URL is not handled. If you do not implement one of the methods, only the return value of the implemented method is considered.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 3.0 and later.

  • Tells the delegate that the app has become active.

    Declaration

    Swift

    optional func applicationDidBecomeActive(_ application: UIApplication)

    Objective-C

    - (void)applicationDidBecomeActive:(UIApplication *)application

    Parameters

    application

    The singleton app object.

    Discussion

    This method is called to let your app know that it moved from the inactive to active state. This can occur because your app was launched by the user or the system. Apps can also return to the active state if the user chooses to ignore an interruption (such as an incoming phone call or SMS message) that sent the app temporarily to the inactive state.

    You should use this method to restart any tasks that were paused (or not yet started) while the app was inactive. For example, you could use it to restart timers or throttle up OpenGL ES frame rates. If your app was previously in the background, you could also use it to refresh your app’s user interface.

    After calling this method, the app also posts a UIApplicationDidBecomeActiveNotification notification to give interested objects a chance to respond to the transition.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Tells the delegate that the app is about to become inactive.

    Declaration

    Swift

    optional func applicationWillResignActive(_ application: UIApplication)

    Objective-C

    - (void)applicationWillResignActive:(UIApplication *)application

    Parameters

    application

    The singleton app object.

    Discussion

    This method is called to let your app know that it is about to move from the active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the app and it begins the transition to the background state. An app in the inactive state continues to run but does not dispatch incoming events to responders.

    You should use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. An app in the inactive state should do minimal work while it waits to transition to either the active or background state.

    If your app has unsaved user data, you can save it here to ensure that it is not lost. However, it is recommended that you save user data at appropriate points throughout the execution of your app, usually in response to specific actions. For example, save data when the user dismisses a data entry screen. Do not rely on specific app state transitions to save all of your app’s critical data.

    After calling this method, the app also posts a UIApplicationWillResignActiveNotification notification to give interested objects a chance to respond to the transition.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Tells the delegate that the app is now in the background.

    Declaration

    Swift

    optional func applicationDidEnterBackground(_ application: UIApplication)

    Objective-C

    - (void)applicationDidEnterBackground:(UIApplication *)application

    Parameters

    application

    The singleton app object.

    Discussion

    Use this method to release shared resources, invalidate timers, and store enough app state information to restore your app to its current state in case it is terminated later. You should also disable updates to your app’s user interface and avoid using some types of shared system resources (such as the user’s contacts database). It is also imperative that you avoid using OpenGL ES in the background.

    Your implementation of this method has approximately five seconds to perform any tasks and return. If you need additional time to perform any final tasks, you can request additional execution time from the system by calling beginBackgroundTaskWithExpirationHandler:. In practice, you should return from applicationDidEnterBackground: as quickly as possible. If the method does not return before time runs out your app is terminated and purged from memory.

    You should perform any tasks relating to adjusting your user interface before this method exits but other tasks (such as saving state) should be moved to a concurrent dispatch queue or secondary thread as needed. Because it's likely any background tasks you start in applicationDidEnterBackground: will not run until after that method exits, you should request additional background execution time before starting those tasks. In other words, first call beginBackgroundTaskWithExpirationHandler: and then run the task on a dispatch queue or secondary thread.

    The app also posts a UIApplicationDidEnterBackgroundNotification notification around the same time it calls this method to give interested objects a chance to respond to the transition.

    For more information about how to transition gracefully to the background, and for information about how to start background tasks, see App Programming Guide for iOS.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 4.0 and later.

  • Tells the delegate that the app is about to enter the foreground.

    Declaration

    Swift

    optional func applicationWillEnterForeground(_ application: UIApplication)

    Objective-C

    - (void)applicationWillEnterForeground:(UIApplication *)application

    Parameters

    application

    The singleton app object.

    Discussion

    In iOS 4.0 and later, this method is called as part of the transition from the background to the active state. You can use this method to undo many of the changes you made to your app upon entering the background. The call to this method is invariably followed by a call to the applicationDidBecomeActive: method, which then moves the app from the inactive to the active state.

    The app also posts a UIApplicationWillEnterForegroundNotification notification shortly before calling this method to give interested objects a chance to respond to the transition.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 4.0 and later.

  • Tells the delegate when the app is about to terminate.

    Declaration

    Swift

    optional func applicationWillTerminate(_ application: UIApplication)

    Objective-C

    - (void)applicationWillTerminate:(UIApplication *)application

    Parameters

    application

    The singleton app object.

    Discussion

    This method lets your app know that it is about to be terminated and purged from memory entirely. You should use this method to perform any final clean-up tasks for your app, such as freeing shared resources, saving user data, and invalidating timers. Your implementation of this method has approximately five seconds to perform any tasks and return. If the method does not return before time expires, the system may kill the process altogether.

    For apps that do not support background execution or are linked against iOS 3.x or earlier, this method is always called when the user quits the app. For apps that support background execution, this method is generally not called when the user quits the app because the app simply moves to the background in that case. However, this method may be called in situations where the app is running in the background (not suspended) and the system needs to terminate it for some reason.

    After calling this method, the app also posts a UIApplicationWillTerminateNotification notification to give interested objects a chance to respond to the transition.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • window window Property

    The window to use when presenting a storyboard.

    Declaration

    Swift

    optional var window: UIWindow? { get set }

    Objective-C

    @property(nonatomic, retain) UIWindow *window

    Discussion

    This property contains the window used to present the app’s visual content on the device’s main screen.

    Implementation of this property is required if your app’s Info.plist file contains the UIMainStoryboardFile key. Fortunately, the Xcode project templates usually include a synthesized declaration of the property automatically for the app delegate. The default value of this synthesized property is nil, which causes the app to create a generic UIWindow object and assign it to the property. If you want to provide a custom window for your app, you must implement the getter method of this property and use it to create and return your custom window.

    For more information about the UIMainStoryboardFile key, see Information Property List Key Reference.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 5.0 and later.

  • Tells the app that it can begin a fetch operation if it has data to download.

    Declaration

    Swift

    optional func application(_ application: UIApplication, performFetchWithCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void)

    Objective-C

    - (void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler

    Parameters

    application

    The singleton app object.

    completionHandler

    The block to execute when the download operation is complete. When calling this block, pass in the fetch result value that best describes the results of your download operation. You must call this handler and should do so as soon as possible. For a list of possible values, see the UIBackgroundFetchResult type.

    Discussion

    Implement this method if your app supports the fetch background mode. When an opportunity arises to download data, the system calls this method to give your app a chance to download any data it needs. Your implementation of this method should download the data, prepare that data for use, and call the block in the completionHandler parameter.

    When this method is called, your app has up to 30 seconds of wall-clock time to perform the download operation and call the specified completion handler block. In practice, your app should call the completion handler block as soon as possible after downloading the needed data. If you do not call the completion handler in time, your app is terminated. More importantly, the system uses the elapsed time to calculate power usage and data costs for your app’s background downloads. If your app takes a long time to call the completion handler, it may be given fewer future opportunities to fetch data in the future. For more information about supporting background fetch operations, see App States and Multitasking in App Programming Guide for iOS.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • Tells the delegate that events related to a URL session are waiting to be processed.

    Declaration

    Swift

    optional func application(_ application: UIApplication, handleEventsForBackgroundURLSession identifier: String, completionHandler completionHandler: () -> Void)

    Objective-C

    - (void)application:(UIApplication *)application handleEventsForBackgroundURLSession:(NSString *)identifier completionHandler:(void (^)(void))completionHandler

    Parameters

    application

    The singleton app object.

    identifier

    The identifier of the URL session requiring attention. If your app was just launched, you can use this identifier to create a new NSURLSession object that can receive the events.

    completionHandler

    The completion handler to call when you finish processing the events. Calling this completion handler lets the system know that your app’s user interface is updated and a new snapshot can be taken.

    Discussion

    The app calls this method when all background transfers associated with an NSURLSession object are done, whether they finished successfully or resulted in an error. The app also calls this method if authentication is required for one or more transfers.

    Use this method to reconnect any URL sessions and to update your app’s user interface. For example, you might use this method to update progress indicators or to incorporate new content into your views. After processing the events, execute the block in the completionHandler parameter so that the app can take a new snapshot of your user interface.

    If a URL session finishes its work when your app is not running, the system launches your app in the background so that it can process the event. In that situation, use the provided identifier to create a new NSURLSessionConfiguration and NSURLSession object. You must configure the other options of your NSURLSessionConfiguration object in the same way that you did when you started the uploads or downloads. Upon creating and configuring the new NSURLSession object, that object calls the appropriate delegate methods to process the events.

    If your app already has a session object with the specified identifier and is running or suspended, you do not need to create a new session object using this method. Suspended apps are moved into the background. As soon as the app is running again, the NSURLSession object with the identifier receives the events and processes them normally.

    At launch time, the app does not call this method if there are uploads or downloads in progress but not yet finished. If you want to display the current progress of those transfers in your app’s user interface, you must recreate the session object yourself. In that situation, cache the identifier value persistently and use it to recreate your session object.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • Tells the delegate that the app successfully registered with Apple Push Notification service (APNs).

    Declaration

    Swift

    optional func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData)

    Objective-C

    - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken

    Parameters

    application

    The app object that initiated the remote-notification registration process.

    deviceToken

    A token that identifies the device to APNs. The token is an opaque data type because that is the form that the provider needs to submit to the APNs servers when it sends a notification to a device. The APNs servers require a binary format for performance reasons.

    The size of a device token is 32 bytes.

    Note that the device token is different from the uniqueIdentifier property of UIDevice because, for security and privacy reasons, it must change when the device is wiped.

    Discussion

    After you call the registerForRemoteNotifications method of the UIApplication object, the app calls this method when device registration completes successfully. In your implementation of this method, connect with your push notification server and give the token to it. APNs pushes notifications only to the device represented by the token.

    The app might call this method in other rare circumstances, such as when the user launches an app after having restored a device from data that is not the device’s backup data. In this exceptional case, the app won’t know the new device’s token until the user launches it.

    For more information about how to implement remote notifications in your app, see Local and Remote Notification Programming Guide.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 3.0 and later.

  • Sent to the delegate when Apple Push Notification service cannot successfully complete the registration process.

    Declaration

    Swift

    optional func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError)

    Objective-C

    - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error

    Parameters

    application

    The app object that initiated the remote-notification registration process.

    error

    An NSError object that encapsulates information why registration did not succeed. The app can choose to display this information to the user.

    Discussion

    After you call the registerForRemoteNotifications method of the UIApplication object, the app calls this method when there is an error in the registration process.

    For more information about how to implement remote notifications in your app, see Local and Remote Notification Programming Guide.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 3.0 and later.

  • Tells the app that a remote notification arrived that indicates there is data to be fetched.

    Declaration

    Swift

    optional func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler handler: (UIBackgroundFetchResult) -> Void)

    Objective-C

    - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))handler

    Parameters

    application

    The singleton app object.

    userInfo

    A dictionary that contains information related to the remote notification, potentially including a badge number for the app icon, an alert sound, an alert message to display to the user, a notification identifier, and custom data. The provider originates it as a JSON-defined dictionary that iOS converts to an NSDictionary object; the dictionary may contain only property-list objects plus NSNull. For more information about the contents of the remote notification dictionary, see Local and Remote Notification Programming Guide.

    handler

    The block to execute when the download operation is complete. When calling this block, pass in the fetch result value that best describes the results of your download operation. You must call this handler and should do so as soon as possible. For a list of possible values, see the UIBackgroundFetchResult type.

    Discussion

    Use this method to process incoming remote notifications for your app. Unlike the application:didReceiveRemoteNotification: method, which is called only when your app is running in the foreground, the system calls this method when your app is running in the foreground or background. In addition, if you enabled the remote notifications background mode, the system launches your app (or wakes it from the suspended state) and puts it in the background state when a remote notification arrives. However, the system does not automatically launch your app if the user has force-quit it. In that situation, the user must relaunch your app or restart the device before the system attempts to launch your app automatically again.

    When a remote notification arrives, the system displays the notification to the user and launches the app in the background (if needed) so that it can call this method. Launching your app in the background gives you time to process the notification and download any data associated with it, minimizing the amount of time that elapses between the arrival of the notification and displaying that data to the user.

    As soon as you finish processing the notification, you must call the block in the handler parameter or your app will be terminated. Your app has up to 30 seconds of wall-clock time to process the notification and call the specified completion handler block. In practice, you should call the handler block as soon as you are done processing the notification. The system tracks the elapsed time, power usage, and data costs for your app’s background downloads. Apps that use significant amounts of power when processing remote notifications may not always be woken up early to process future notifications.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • Tells the app delegate to perform the custom action specified by a remote notification.

    Declaration

    Swift

    optional func application(_ application: UIApplication, handleActionWithIdentifier identifier: String?, forRemoteNotification userInfo: [NSObject : AnyObject], completionHandler completionHandler: () -> Void)

    Objective-C

    - (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void (^)(void))completionHandler

    Parameters

    application

    The app object that received the remote notification.

    identifier

    The identifier associated with the custom action.

    userInfo

    A dictionary that contains information related to the remote notification. This dictionary originates from the provider as a JSON-defined dictionary, which iOS converts to an NSDictionary object before calling this method. The contents of the dictionary are the remote notification payload, which consists only of property-list objects plus NSNull. For more information about the contents of the remote notification dictionary, see Local and Remote Notification Programming Guide.

    completionHandler

    The block to execute when you are finished performing the specified action. You must call this block at the end of your method.

    Discussion

    The app calls this method when the user taps an action button in an alert displayed in response to a remote notification. Remote notifications that include a category key in their payload display buttons for the actions in the corresponding category. If the user taps one of those buttons, the system wakes up the app (launching it if needed) and calls this method in the background. Your implementation of this method should perform the action associated with the specified identifier and execute the block in the completionHandler parameter as soon as you are done. Failure to execute the completion handler block at the end of your implementation will cause your app to be terminated.

    To configure the actions for a given category, create a UIUserNotificationActionSettings object and register it with the app when you call the registerUserNotificationSettings: method.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 8.0 and later.

  • Tells the delegate that the running app received a remote notification.

    Declaration

    Swift

    optional func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject])

    Objective-C

    - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo

    Parameters

    application

    The app object that received the remote notification.

    userInfo

    A dictionary that contains information related to the remote notification, potentially including a badge number for the app icon, an alert sound, an alert message to display to the user, a notification identifier, and custom data. The provider originates it as a JSON-defined dictionary that iOS converts to an NSDictionary object; the dictionary may contain only property-list objects plus NSNull.

    Discussion

    Implement the application:didReceiveRemoteNotification:fetchCompletionHandler: method instead of this one whenever possible. If your delegate implements both methods, the app object calls the application:didReceiveRemoteNotification:fetchCompletionHandler: method.

    If the app is running, the app calls this method to process incoming remote notifications. The userInfo dictionary contains the aps key whose value is another dictionary with the remaining notification data. Although you should not need the information in the aps dictionary, you can retrieve its contents using the following keys:

    • alert—The value is either a string for the alert message or a dictionary with two keys: body and show-view. The value of the body key is a string containing the alert message and the value of the show-view key is a Boolean. If the value of the show-view key is false, the alert’s View button is not shown. The default is to show the View button which, if the user taps it, launches the app.

    • badge—A number indicating the quantity of data items to download from the provider. This number is to be displayed on the app icon. The absence of a badge property indicates that any number currently badging the icon should be removed.

    • sound—The name of a sound file in the app bundle to play as an alert sound. If “default” is specified, the default sound should be played.

    The userInfo dictionary may also have custom data defined by the provider according to the JSON schema. The properties for custom data should be specified at the same level as the aps dictionary. However, custom-defined properties should not be used for mass data transport because there is a strict size limit per notification (256 bytes) and delivery is not guaranteed.

    If the app is not running when a remote notification arrives, the method launches the app and provides the appropriate information in the launch options dictionary. The app does not call this method to handle that remote notification. Instead, your implementation of the application:willFinishLaunchingWithOptions: or application:didFinishLaunchingWithOptions: method needs to get the remote notification payload data and respond appropriately.

    For more information about how to implement remote notifications in your app, see Local and Remote Notification Programming Guide.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 3.0 and later.

  • Sent to the delegate when a running app receives a local notification.

    Declaration

    Swift

    optional func application(_ application: UIApplication, didReceiveLocalNotification notification: UILocalNotification)

    Objective-C

    - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification

    Parameters

    application

    The app object that received the local notification.

    notification

    A local notification that encapsulates details about the notification, potentially including custom data.

    Discussion

    Local notifications are similar to remote notifications, but differ in that they are scheduled, displayed, and received entirely on the same device. An app can create and schedule a local notification, and the operating system then delivers it at the scheduled date and time. If the app is not active in the foreground when the notification fires, the system uses the information in the UILocalNotification object to determine whether it should display an alert, badge the app icon, or play a sound. If the app is running in the foreground, the system calls this method directly without alerting the user in any way.

    You might implement this method in your delegate if you want to be notified that a local notification occurred. For example, a calendar app might use local notifications to alert the user to upcoming events.

    If the user chooses to open the app when a local notification occurs, the launch options dictionary passed to the application:willFinishLaunchingWithOptions: and application:didFinishLaunchingWithOptions: methods contains the UIApplicationLaunchOptionsLocalNotificationKey key. This method is called at some point after your delegate’s application:didFinishLaunchingWithOptions: method.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 4.0 and later.

  • Tells the delegate that the user selected a custom action from the alert panel of a local notification.

    Declaration

    Swift

    optional func application(_ application: UIApplication, handleActionWithIdentifier identifier: String?, forLocalNotification notification: UILocalNotification, completionHandler completionHandler: () -> Void)

    Objective-C

    - (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(UILocalNotification *)notification completionHandler:(void (^)(void))completionHandler

    Parameters

    application

    The app object that received the local notification.

    identifier

    The identifier associated with the custom action. This string corresponds to the identifier from the UILocalNotificationAction object that was used to configure the action in the local notification.

    notification

    The local notification object that was triggered.

    completionHandler

    A block to call when you are finished performing the action.

    Discussion

    The app calls this method when the user taps an action button in an alert displayed in response to a local notification. Local notifications that include a registered category name in their category property display buttons for the actions in that category. If the user taps one of those buttons, the system wakes up the app (launching it if needed) and calls this method in the background. Your implementation of this method should perform the action associated with the specified identifier and execute the block in the completionHandler parameter as soon as you are done. Failure to execute the completion handler block at the end of your implementation will cause your app to be terminated.

    To configure the actions for a given category, create a UIUserNotificationActionSettings object and register it with the app when you call the registerUserNotificationSettings: method.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 8.0 and later.

  • Tells the delegate what types of notifications may be used to get the user’s attention.

    Declaration

    Swift

    optional func application(_ application: UIApplication, didRegisterUserNotificationSettings notificationSettings: UIUserNotificationSettings)

    Objective-C

    - (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings

    Parameters

    application

    The app object that registered the user notification settings.

    notificationSettings

    The user notification settings that are available to your app. The settings in this object may be different than the ones you originally requested.

    Discussion

    Apps that use local or remote notifications to alert the user to new information must register the types of notifications they want to use by calling the registerUserNotificationSettings: method of the app object. (In apps that link on versions of iOS prior to 8.0, registration can also happen implicitly when you schedule a local notification.) Your app’s request is combined with the user’s current preferences to determine what notification types are allowed and the results are delivered to this method in the notificationSettings parameter.

    The first time you register your app’s preferred notification types, the system asks the user whether your app should be allowed to deliver notifications and stores the user’s response. The system does not prompt the user during subsequent registration attempts. The user can always change the notification preferences using the Settings app.

    Because the user’s preferences can change, you should always check the contents of the notificationSettings parameter. These settings control only whether the user is notified about a local or remote notification. The notification is still delivered to your app at the appropriate times.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 8.0 and later.

  • Tells the delegate when the app receives a memory warning from the system.

    Declaration

    Swift

    optional func applicationDidReceiveMemoryWarning(_ application: UIApplication)

    Objective-C

    - (void)applicationDidReceiveMemoryWarning:(UIApplication *)application

    Parameters

    application

    The singleton app object.

    Discussion

    Your implementation of this method should free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later. You use this method in conjunction with the didReceiveMemoryWarning of the UIViewController class and the UIApplicationDidReceiveMemoryWarningNotification notification to release memory throughout your app.

    It is strongly recommended that you implement this method. If your app does not release enough memory during low-memory conditions, the system may terminate it outright.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Tells the delegate when there is a significant change in the time.

    Declaration

    Swift

    optional func applicationSignificantTimeChange(_ application: UIApplication)

    Objective-C

    - (void)applicationSignificantTimeChange:(UIApplication *)application

    Parameters

    application

    The singleton app object.

    Discussion

    Examples of significant time changes include the arrival of midnight, an update of the time by a carrier, and the change to daylight savings time. The delegate can implement this method to adjust any object of the app that displays time or is sensitive to time changes.

    Prior to calling this method, the app also posts a UIApplicationSignificantTimeChangeNotification notification to give interested objects a chance to respond to the change.

    If your app is currently suspended, this message is queued until your app returns to the foreground, at which point it is delivered. If multiple time changes occur, only the most recent one is delivered.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Asks the delegate to respond to a request from a paired WatchKit app.

    Declaration

    Swift

    optional func application(_ application: UIApplication, handleWatchKitExtensionRequest userInfo: [NSObject : AnyObject]?, reply reply: (([NSObject : AnyObject]!) -> Void)!)

    Objective-C

    - (void)application:(UIApplication *)application handleWatchKitExtensionRequest:(NSDictionary *)userInfo reply:(void (^)(NSDictionary *replyInfo))reply

    Parameters

    application

    The singleton app object.

    userInfo

    A dictionary provided by the WatchKit app with the request information. Use the data in this dictionary to process the request from the WatchKit app.

    reply

    A block to execute with the results of the request. This block has no return value and takes the following parameter:

    replyInfo

    A dictionary containing data to return to the WatchKit app. The contents of the dictionary must be serializable to a property list file. The contents of this dictionary are at your discretion and you may specify nil.

    Discussion

    If your iOS app and WatchKit app coordinate efforts to perform certain tasks, implement this method and use it to respond to requests from the WatchKit app. After finishing the request, execute the provided reply block (if any) to return the results.

    Because this method is likely to be called while your app is in the background, call the beginBackgroundTaskWithName:expirationHandler: method at the start of your implementation and the endBackgroundTask: method after you have processed the reply and executed the reply block. Starting a background task ensures that your app is not suspended before it has a chance to send its reply.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 8.2 and later.

  • Asks the delegate whether the app’s state should be preserved.

    Declaration

    Swift

    optional func application(_ application: UIApplication, shouldSaveApplicationState coder: NSCoder) -> Bool

    Objective-C

    - (BOOL)application:(UIApplication *)application shouldSaveApplicationState:(NSCoder *)coder

    Parameters

    application

    The singleton app object.

    coder

    The keyed archiver into which you can put high-level state information.

    Return Value

    YEStrue if the app’s state should be preserved or NOfalse if it should not.

    Discussion

    Apps must implement this method and the application:shouldRestoreApplicationState: method for state preservation to occur. In addition, your implementation of this method must return YEStrue each time UIKit tries to preserve the state of your app. You can return NOfalse to disable state preservation temporarily. For example, during testing, you could disable state preservation to test specific code paths.

    You can add version information or any other contextual data to the provided coder object as needed. During restoration, you can use that information to help decide whether or not to proceed with restoring your app to its previous state.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 6.0 and later.

  • Asks the delegate whether the app’s saved state information should be restored.

    Declaration

    Swift

    optional func application(_ application: UIApplication, shouldRestoreApplicationState coder: NSCoder) -> Bool

    Objective-C

    - (BOOL)application:(UIApplication *)application shouldRestoreApplicationState:(NSCoder *)coder

    Parameters

    application

    The singleton app object.

    coder

    The keyed archiver containing the app’s previously saved state information.

    Return Value

    YEStrue if the app’s state should be restored or NOfalse if it should not.

    Discussion

    Apps must implement this method and the application:shouldSaveApplicationState: method for state preservation to occur. In addition, your implementation of this method must return YEStrue each time UIKit tries to restore the state of your app. You can use the information in the provided coder object to decide whether or not to proceed with state restoration. For example, you might return NOfalse if the data in the coder is from a different version of your app and cannot be effectively restored to the current version.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 6.0 and later.

  • Asks the delegate to provide the specified view controller.

    Declaration

    Swift

    optional func application(_ application: UIApplication, viewControllerWithRestorationIdentifierPath identifierComponents: [AnyObject], coder coder: NSCoder) -> UIViewController?

    Objective-C

    - (UIViewController *)application:(UIApplication *)application viewControllerWithRestorationIdentifierPath:(NSArray *)identifierComponents coder:(NSCoder *)coder

    Parameters

    application

    The singleton app object.

    identifierComponents

    An array of NSString objects corresponding to the restoration identifiers of the desired view controller and all of its ancestors in the view controller hierarchy. The last value in the array is the restoration identifier of the desired view controller. Earlier entries represent the restoration identifiers of its ancestors.

    coder

    The keyed archiver containing the app’s saved state information.

    Return Value

    The view controller object to use or nil if the app delegate does not supply this view controller. If this method returns nil, UIKit tries to find the view controller implicitly using the available restoration path and storyboard information.

    Discussion

    During state restoration, when UIKit encounters a view controller without a restoration class, it calls this method to ask for the corresponding view controller object. Your implementation of this method should create (or find) the corresponding view controller object and return it. If your app delegate does not provide the view controller, return nil.

    You use the strings in the identifierComponents parameter to identify the view controller being requested. The view controllers in your app form a hierarchy. At the root of this hierarchy is the window’s root view controller, which itself may present or embed other view controllers. Those presented or embedded view controllers may themselves present and embed other view controllers. The result is a hierarchy of view controller relationships, with each presented or embedded view controller becoming a child of the view controller that presented or embedded it. The strings in the identifierComponents array identify the path through this hierarchy from the root view controller to the desired view controller.

    It is not always necessary to create a new view controller object in your implementation of this method. You can also return an existing view controller object that was created by another means. For example, you would always return the existing view controllers loaded from your app’s main storyboard file rather than create new objects.

    Your implementation of this method may use any data in the provided coder to assist in the restoration process. However, you usually do not need to restore the entire state of the view controller at this point. During a later pass, view controllers that define a decodeRestorableStateWithCoder: method are normally given a chance to restore their state form the same coder object. Similarly, the app delegate itself has a application:didDecodeRestorableStateWithCoder: method that you can use to restore app-level state information.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 6.0 and later.

  • Tells your delegate to save any high-level state information at the beginning of the state preservation process.

    Declaration

    Swift

    optional func application(_ application: UIApplication, willEncodeRestorableStateWithCoder coder: NSCoder)

    Objective-C

    - (void)application:(UIApplication *)application willEncodeRestorableStateWithCoder:(NSCoder *)coder

    Parameters

    application

    The singleton app object.

    coder

    The keyed archiver in which to write any state information.

    Discussion

    The state preservation system calls this method at the beginning of the preservation process. This is your opportunity to add any app-level information to state information. For example, you might use this method to write version information or the high-level configuration of your app.

    Your implementation of this method can encode restorable view and view controller objects that it needs to reference. Encoding a restorable view or view controller writes that object’s restoration identifier to the coder. (That identifier is used during the decode process to locate the new version of the object.) If the view or view controller defines a encodeRestorableStateWithCoder: method, that method is also called at some point so that the object can encode its own state.

    Apart from views and view controllers, other objects follow the normal serialization process and must adopt the NSCoding protocol before they can be encoded. Encoding such objects embeds the object’s contents in the archive directly. During the decode process, a new object is created and initialized with the data from the archive.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 6.0 and later.

  • Tells your delegate to restore any high-level state information as part of the state restoration process.

    Declaration

    Swift

    optional func application(_ application: UIApplication, didDecodeRestorableStateWithCoder coder: NSCoder)

    Objective-C

    - (void)application:(UIApplication *)application didDecodeRestorableStateWithCoder:(NSCoder *)coder

    Parameters

    application

    The singleton app object.

    coder

    The keyed archiver containing the app’s previously saved state information.

    Discussion

    The state restoration system calls this method as the final step in the state restoration process. By the time this method is called, all other restorable objects will have been restored and put back into their previous state. You can use this method to read any high-level app data you saved in the application:willEncodeRestorableStateWithCoder: method and apply it to your app.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 6.0 and later.

  • Asks the delegate to open a resource identified by URL.

    Declaration

    Swift

    optional func application(_ application: UIApplication, openURL url: NSURL, sourceApplication sourceApplication: String?, annotation annotation: AnyObject?) -> Bool

    Objective-C

    - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation

    Parameters

    application

    The singleton app object.

    url

    The URL resource to open. This resource can be a network resource or a file. For information about the Apple-registered URL schemes, see Apple URL Scheme Reference.

    sourceApplication

    The bundle ID of the app that is requesting your app to open the URL (url).

    annotation

    A property list object supplied by the source app to communicate information to the receiving app.

    Return Value

    YEStrue if the delegate successfully handled the request or NOfalse if the attempt to open the URL resource failed.

    Discussion

    Your implementation of this method should open the specified URL and update its user interface accordingly. If your app had to be launched to open the URL, the app calls the application:willFinishLaunchingWithOptions: and application:didFinishLaunchingWithOptions: methods first, followed by this method. The return values of those methods can be used to prevent this method from being called. (If the app is already running, only this method is called.)

    If the URL refers to a file that was opened through a document interaction controller, the annotation parameter may contain additional data that the source app wanted to send along with the URL. The format of this data is defined by the app that sent it but the data must consist of objects that can be put into a property list.

    Files sent to your app through AirDrop or a document interaction controller are placed in the Documents/Inbox directory of your app’s home directory. Your app has permission to read and delete files in this directory but does not have permission to write to them. If you want to modify a file, you must move it to a different directory first. In addition, files in that directory are usually encrypted using data protection. If the file is protected and the user locks the device before this method is called, you will be unable to read the file’s contents immediately. In that case, you should save the URL and try to open the file later rather than return NOfalse from this method. Use the protectedDataAvailable property of the app object to determine if data protection is currently enabled.

    There is no matching notification for this method.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 4.2 and later.

  • Tells the delegate that the user wants to continue an activity whose data might not yet be available.

    Declaration

    Swift

    optional func application(_ application: UIApplication, willContinueUserActivityWithType userActivityType: String) -> Bool

    Objective-C

    - (BOOL)application:(UIApplication *)application willContinueUserActivityWithType:(NSString *)userActivityType

    Parameters

    application

    The shared app object.

    userActivityType

    The requested activity type.

    Return Value

    YEStrue if you notify the user that your app is about to continue the activity or NOfalse if you want iOS to notify the user.

    Discussion

    Use this method to provide immediate feedback to the user that an activity is about to continue on this device. The app calls this method as soon as the user confirms that an activity should be continued but possibly before the data associated with that activity is available.

    Your implementation of this method should prepare to initiate the activity. If you notify the user as part of your preparations, return YEStrue from this method so that iOS does not display its own notification. If you do not implement this method or your implementation returns NOfalse, iOS displays its own notification to the user.

    This method is not called if either application:willFinishLaunchingWithOptions: or application:didFinishLaunchingWithOptions: returns NOfalse.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 8.0 and later.

  • Tells the delegate that the data for continuing an activity is available.

    Declaration

    Swift

    optional func application(_ application: UIApplication, continueUserActivity userActivity: NSUserActivity, restorationHandler restorationHandler: ([AnyObject]!) -> Void) -> Bool

    Objective-C

    - (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray *restorableObjects))restorationHandler

    Parameters

    application

    The shared app object.

    userActivity

    The activity object containing the data associated with the task the user was performing. Use the data in this object to recreate what the user was doing.

    restorationHandler

    A block to execute if your app creates objects to perform the task. Calling this block is optional and you can copy this block and call it at a later time. When calling a saved copy of the block, you must call it from the app’s main thread. This block has no return value and takes the following parameter:

    restorableObjects

    An array of UIResponder objects representing objects you created or fetched in order to perform the operation. The system calls the restoreUserActivityState: method of each object in the array to give it a chance to perform the operation.

    Return Value

    YEStrue to indicate that your app handled the activity or NOfalse to let iOS know that your app did not handle the activity.

    Discussion

    The app calls this method when it receives the data associated with the user activity. This method is your opportunity to update your app so that it can perform the associated task. If you do not implement this method or if your implementation returns NOfalse, iOS tries to create a document for your app to open using a URL.

    Calling the block in the restorationHandler is optional and is only needed when specific objects are capable of continuing the activity.

    This method is not called if either application:willFinishLaunchingWithOptions: or application:didFinishLaunchingWithOptions: returns NOfalse.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 8.0 and later.

  • Tells the delegate that the activity was updated. (required)

    Declaration

    Swift

    optional func application(_ application: UIApplication, didUpdateUserActivity userActivity: NSUserActivity)

    Objective-C

    - (void)application:(UIApplication *)application didUpdateUserActivity:(NSUserActivity *)userActivity

    Parameters

    application

    The shared app object.

    userActivity

    The activity object containing the data associated with the task the user was performing.

    Discussion

    This method is called on the main thread when a user activity managed by UIKit has been updated. You can implement this method as a final opportunity to add data to the user activity object.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 8.0 and later.

  • Tells the delegate that the activity could not be continued.

    Declaration

    Swift

    optional func application(_ application: UIApplication, didFailToContinueUserActivityWithType userActivityType: String, error error: NSError)

    Objective-C

    - (void)application:(UIApplication *)application didFailToContinueUserActivityWithType:(NSString *)userActivityType error:(NSError *)error

    Parameters

    application

    The shared app object.

    userActivityType

    The activity type that was attempted.

    error

    An error object indicating the reason for the failure.

    Discussion

    Use this method to let the user know that the specified activity could not be continued. If you do not implement this method, UIKit displays an error to the user with an appropriate message about the reason for the failure.

    This method is not called if either application:willFinishLaunchingWithOptions: or application:didFinishLaunchingWithOptions: returns NOfalse.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 8.0 and later.

  • Asks the delegate to grant permission to use app extensions that are based on a specified extension point identifier. (required)

    Declaration

    Swift

    optional func application(_ application: UIApplication, shouldAllowExtensionPointIdentifier extensionPointIdentifier: String) -> Bool

    Objective-C

    - (BOOL)application:(UIApplication *)application shouldAllowExtensionPointIdentifier:(NSString *)extensionPointIdentifier

    Parameters

    application

    The shared app object.

    extensionPointIdentifier

    A constant identifying an extension point.

    Return Value

    NOfalse to disallow use of a specified app extension type, or YEStrue to allow use of the type.

    Discussion

    You can implement this method to reject a specified type of app extension, based on its extension point identifier, from use in your app. See Extension Point Identifier Constants in UIApplication Class Reference.

    If you do not implement this method, all app extension types are available for use in your app.

    In iOS 8.0, the only type of app extension you can reject is the custom keyboard. For information on app extensions, see App Extension Programming Guide.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 8.0 and later.

  • Tells the delegate that the protected files are about to become unavailable.

    Declaration

    Swift

    optional func applicationProtectedDataWillBecomeUnavailable(_ application: UIApplication)

    Objective-C

    - (void)applicationProtectedDataWillBecomeUnavailable:(UIApplication *)application

    Parameters

    application

    The singleton app object.

    Discussion

    On a device that uses content protection, protected files are stored in an encrypted form and made available only at certain times, usually when the device is unlocked. This notification lets your app know that the device is about to be locked and that any protected files it is currently accessing might become unavailable shortly.

    If your app is currently accessing a protected file, you can use this method to release any references to that file. Although it is not an error to access the file while the device is locked, any attempts to do so will fail. Therefore, if your app depends on the file, you might want to take steps to avoid using that file while the device is locked.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 4.0 and later.

  • Tells the delegate that protected files are available now.

    Declaration

    Swift

    optional func applicationProtectedDataDidBecomeAvailable(_ application: UIApplication)

    Objective-C

    - (void)applicationProtectedDataDidBecomeAvailable:(UIApplication *)application

    Parameters

    application

    The singleton app object.

    Discussion

    On a device that uses content protection, protected files are stored in an encrypted form and made available only at certain times, usually when the device is unlocked. This notification lets your app know that the device is now unlocked and that you may access certain types of protected files again.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 4.0 and later.

  • Asks the delegate for the interface orientations to use for the view controllers in the specified window.

    Declaration

    Swift

    optional func application(_ application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> Int

    Objective-C

    - (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window

    Parameters

    application

    The singleton app object.

    window

    The window whose interface orientations you want to retrieve.

    Return Value

    A bit mask of the UIInterfaceOrientationMask constants that indicate the orientations to use for the view controllers.

    Discussion

    This method returns the total set of interface orientations supported by the app. When determining whether to rotate a particular view controller, the orientations returned by this method are intersected with the orientations supported by the root view controller or topmost presented view controller. The app and view controller must agree before the rotation is allowed.

    If you do not implement this method, the app uses the values in the UIInterfaceOrientation key of the app’s Info.plist as the default interface orientations.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 6.0 and later.

  • Keys used to access values in the launch options dictionary passed to the application:willFinishLaunchingWithOptions: and application:didFinishLaunchingWithOptions: methods of the app delegate.

    Declaration

    Swift

    let UIApplicationLaunchOptionsURLKey: String let UIApplicationLaunchOptionsSourceApplicationKey: String let UIApplicationLaunchOptionsRemoteNotificationKey: String let UIApplicationLaunchOptionsAnnotationKey: String let UIApplicationLaunchOptionsLocalNotificationKey: String let UIApplicationLaunchOptionsLocationKey: String let UIApplicationLaunchOptionsNewsstandDownloadsKey: String let UIApplicationLaunchOptionsBluetoothCentralsKey: String let UIApplicationLaunchOptionsBluetoothPeripheralsKey: String let UIApplicationLaunchOptionsUserActivityDictionaryKey: String let UIApplicationLaunchOptionsUserActivityTypeKey: String

    Objective-C

    NSString *const UIApplicationLaunchOptionsURLKey; NSString *const UIApplicationLaunchOptionsSourceApplicationKey; NSString *const UIApplicationLaunchOptionsRemoteNotificationKey; NSString *const UIApplicationLaunchOptionsAnnotationKey; NSString *const UIApplicationLaunchOptionsLocalNotificationKey; NSString *const UIApplicationLaunchOptionsLocationKey; NSString *const UIApplicationLaunchOptionsNewsstandDownloadsKey; NSString *const UIApplicationLaunchOptionsBluetoothCentralsKey; NSString *const UIApplicationLaunchOptionsBluetoothPeripheralsKey; NSString *const UIApplicationLaunchOptionsRemoteVoIPKey; NSString *const UIApplicationLaunchOptionsUserActivityDictionaryKey; NSString *const UIApplicationLaunchOptionsUserActivityTypeKey;

    Constants

    • UIApplicationLaunchOptionsURLKey

      UIApplicationLaunchOptionsURLKey

      The presence of this key indicates that the app was launched in order to open a URL. The value of this key is an NSURL object containing the URL to open.

      This key is also used to access the same value in the userInfo dictionary of the notification named UIApplicationDidFinishLaunchingNotification.

      Available in iOS 3.0 and later.

    • UIApplicationLaunchOptionsSourceApplicationKey

      UIApplicationLaunchOptionsSourceApplicationKey

      The presence of this key identifies the app that requested the launch of your app. The value of this key is an NSString object that represents the bundle ID of the app that made the request.

      This key is also used to access the same value in the userInfo dictionary of the notification named UIApplicationDidFinishLaunchingNotification.

      Available in iOS 3.0 and later.

    • UIApplicationLaunchOptionsRemoteNotificationKey

      UIApplicationLaunchOptionsRemoteNotificationKey

      The presence of this key indicates that a remote notification is available for the app to process. The value of this key is an NSDictionary containing the payload of the remote notification. See the description of application:didReceiveRemoteNotification: for further information about handling remote notifications.

      This key is also used to access the same value in the userInfo dictionary of the notification named UIApplicationDidFinishLaunchingNotification.

      Available in iOS 3.0 and later.

    • UIApplicationLaunchOptionsAnnotationKey

      UIApplicationLaunchOptionsAnnotationKey

      The presence of this key indicates that custom data was provided by the app that requested the opening of the URL. The value of this key is a property-list object containing the custom data. The same object is also passed to the annotation parameter of the application:openURL:sourceApplication:annotation: method. The contents of this property-list object are specific to the app that made the request.

      Available in iOS 3.2 and later.

    • UIApplicationLaunchOptionsLocalNotificationKey

      UIApplicationLaunchOptionsLocalNotificationKey

      The presence of this key indicates that a local notification is available for the app to process. The value of this key is the UILocalNotification object that was triggered. For additional information about handling local notifications, see the application:didReceiveLocalNotification: method.

      This key is also used to access the same value in the userInfo dictionary of the notification named UIApplicationDidFinishLaunchingNotification.

      Available in iOS 4.0 and later.

    • UIApplicationLaunchOptionsLocationKey

      UIApplicationLaunchOptionsLocationKey

      The presence of this key indicates that the app was launched in response to an incoming location event. The value of this key is an NSNumber object containing a Boolean value. You should use the presence of this key as a signal to create a CLLocationManager object and start location services again. Location data is delivered only to the location manager delegate and not using this key.

      Available in iOS 4.0 and later.

    • UIApplicationLaunchOptionsNewsstandDownloadsKey

      UIApplicationLaunchOptionsNewsstandDownloadsKey

      The presence of this key indicates that newly downloaded Newsstand assets are available for your app. The value of this key is an array of string identifiers that identify the NKAssetDownload objects corresponding to the assets. Although you can use the identifiers for cross-checking purposes, you should obtain the definitive array of NKAssetDownload objects (representing asset downloads in progress or in error) through the downloadingAssets property of the NKLibrary object representing the Newsstand app’s library.

      Available in iOS 5.0 and later.

    • UIApplicationLaunchOptionsBluetoothCentralsKey

      UIApplicationLaunchOptionsBluetoothCentralsKey

      The presence of this key indicates that the app previously had one or more CBCentralManager objects and was relaunched by the Bluetooth system to continue actions associated with those objects. The value of this key is an NSArray object containing one or more NSString objects.

      Each string in the array represents the restoration identifier for a central manager object. This is the same string you assigned to the CBCentralManagerOptionRestoreIdentifierKey key when you initialized the central manager object previously. The system provides the restoration identifiers only for central managers that had active or pending peripheral connections or were scanning for peripherals.

      Available in iOS 7.0 and later.

    • UIApplicationLaunchOptionsBluetoothPeripheralsKey

      UIApplicationLaunchOptionsBluetoothPeripheralsKey

      The presence of this key indicates that the app previously had one or more CBPeripheralManager objects and was relaunched by the Bluetooth system to continue actions associated with those objects. The value of this key is an NSArray object containing one or more NSString objects.

      Each string in the array represents the restoration identifier for a peripheral manager object. This is the same string you assigned to the CBPeripheralManagerOptionRestoreIdentifierKey key when you initialized the peripheral manager object previously. The system provides the restoration identifiers only for peripheral managers that had published or advertised services.

      Available in iOS 7.0 and later.

    • UIApplicationLaunchOptionsUserActivityDictionaryKey

      UIApplicationLaunchOptionsUserActivityDictionaryKey

      The presence of this key indicates that the app was launched in order to continue a user activity. The value of this key is an NSDictionary object containing the key UIApplicationLaunchOptionsUserActivityTypeKey, whose value is an NSString object identifying the activity type.

      Available in iOS 8.0 and later.

    • UIApplicationLaunchOptionsUserActivityTypeKey

      UIApplicationLaunchOptionsUserActivityTypeKey

      This key is used in the subdictionary which is the value of UIApplicationLaunchOptionsUserActivityDictionaryKey. The value of this key is an NSString object identifying the activity type.

      Available in iOS 8.0 and later.