Protocol

UIApplicationDelegate

A set of methods that you use to manage shared behaviors for your app.

Declaration

@protocol UIApplicationDelegate

Overview

Your app delegate object manages your app’s shared behaviors. The app delegate is effectively the root object of your app, and it works in conjunction with UIApplication to manage some interactions with the system. Like the UIApplication object, UIKit creates your app delegate object early in your app’s launch cycle so it is always present.

Use your app delegate object to handle the following tasks:

  • Initializing your app’s central data structures.

  • Configuring your app’s scenes.

  • Responding to notifications originating from outside the app, such as low-memory warnings, download completion notifications, and more.

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

  • Registering for any required services at launch time, such as Apple Push Notification service.

For more information about how you use the app delegate object to initialize your app at launch time, see Responding to the Launch of Your App.

Life Cycle Management in iOS 12 and Earlier

In iOS 12 and earlier, you use your app delegate to manage major life cycle events in your app. Specifically, you use methods of the app delegate to update the state of your app when it enters the foreground or moves to the background.

Topics

Initializing the App

- application:willFinishLaunchingWithOptions:

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

- application:didFinishLaunchingWithOptions:

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

UIApplicationLaunchOptionsKey

Keys used to access values in the launch options dictionary passed to your app at initialization time.

- applicationDidFinishLaunching:

Tells the delegate when the app has finished launching. Don’t use. Instead, use application:didFinishLaunchingWithOptions:.

UIApplicationDidFinishLaunchingNotification

Posted immediately after the app finishes launching.

Configuring and Discarding Scenes

- application:configurationForConnectingSceneSession:options:

Returns the configuration data for UIKit to use when creating a new scene.

Beta
- application:didDiscardSceneSessions:

Tells the delegate that the user closed one or more of the app's scenes from the app switcher.

Beta

Responding to App Life-Cycle Events

- applicationDidBecomeActive:

Tells the delegate that the app has become active.

- applicationWillResignActive:

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

- applicationDidEnterBackground:

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

- applicationWillEnterForeground:

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

- applicationWillTerminate:

Tells the delegate when the app is about to terminate.

UIApplicationDidBecomeActiveNotification

Posted when the app becomes active.

UIApplicationDidEnterBackgroundNotification

Posted when the app enters the background.

UIApplicationWillEnterForegroundNotification

Posted shortly before an app leaves the background state on its way to becoming the active app.

UIApplicationWillResignActiveNotification

Posted when the app is no longer active and loses focus.

UIApplicationWillTerminateNotification

Posted when the app is about to terminate.

Responding to Environment Changes

- applicationProtectedDataDidBecomeAvailable:

Tells the delegate that protected files are available now.

- applicationProtectedDataWillBecomeUnavailable:

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

- applicationDidReceiveMemoryWarning:

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

- applicationSignificantTimeChange:

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

UIApplicationProtectedDataDidBecomeAvailable

Posted when the protected files become available for your code to access.

UIApplicationProtectedDataWillBecomeUnavailable

Posted shortly before protected files are locked down and become inaccessible.

UIApplicationDidReceiveMemoryWarningNotification

Posted when the app receives a warning from the operating system about low memory availability.

UIApplicationSignificantTimeChangeNotification

Posted when there is a significant change in time, for example, change to a new day (midnight), carrier time update, and change to or from daylight savings time.

Managing App State Restoration

- application:shouldSaveApplicationState:

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

- application:shouldRestoreApplicationState:

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

- application:viewControllerWithRestorationIdentifierPath:coder:

Asks the delegate to provide the specified view controller.

- application:willEncodeRestorableStateWithCoder:

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

- application:didDecodeRestorableStateWithCoder:

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

UIApplicationStateRestorationBundleVersionKey

The version of your app responsible for creating the restoration archive.

UIApplicationStateRestorationSystemVersionKey

The version of the system on which your app created the restoration archive.

UIApplicationStateRestorationTimestampKey

The time at which your app created the restoration archive.

UIApplicationStateRestorationUserInterfaceIdiomKey

The user interface idiom that was in effect when your app created the restoration archive.

UIStateRestorationViewControllerStoryboardKey

A reference to the storyboard that contains the view controller.

Downloading Data in the Background

- application:performFetchWithCompletionHandler:

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

Deprecated
- application:handleEventsForBackgroundURLSession:completionHandler:

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

UIBackgroundFetchResult

Constants that indicate the result of a background fetch operation.

Handling Remote Notification Registration

- application:didRegisterForRemoteNotificationsWithDeviceToken:

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

- application:didFailToRegisterForRemoteNotificationsWithError:

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

- application:didReceiveRemoteNotification:fetchCompletionHandler:

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

Continuing User Activity and Handling Quick Actions

- application:willContinueUserActivityWithType:

Tells the delegate if your app takes responsibility for notifying users when a continuation activity takes longer than expected.

- application:continueUserActivity:restorationHandler:

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

- application:didUpdateUserActivity:

Tells the delegate that the activity was updated.

- application:didFailToContinueUserActivityWithType:error:

Tells the delegate that the activity could not be continued.

- application:performActionForShortcutItem:completionHandler:

Called when the user selects a Home screen quick action for your app, except when you’ve intercepted the interaction in a launch method.

Interacting With WatchKit

- application:handleWatchKitExtensionRequest:reply:

Asks the delegate to respond to a request from a paired watchOS app.

Interacting With HealthKit

- applicationShouldRequestHealthAuthorization:

Called when your app should ask the user for access to his or her HealthKit data.

Opening a URL-Specified Resource

- application:openURL:options:

Asks the delegate to open a resource specified by a URL, and provides a dictionary of launch options.

UIApplicationOpenURLOptionsKey

Keys used to access values in the options dictionary when opening a URL.

Disallowing Specified App Extension Types

- application:shouldAllowExtensionPointIdentifier:

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

UIApplicationKeyboardExtensionPointIdentifier

The identifier for custom keyboards.

Handling SiriKit Intents

- application:handleIntent:completionHandler:

Asks the delegate to handle the specified SiriKit intent directly.

Handling CloudKit Invitations

- application:userDidAcceptCloudKitShareWithMetadata:

Tells the delegate that the app now has access to shared information in CloudKit.

Managing Interface Geometry

- application:supportedInterfaceOrientationsForWindow:

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

- application:willChangeStatusBarOrientation:duration:

Tells the delegate when the interface orientation of the status bar is about to change.

Deprecated
- application:didChangeStatusBarOrientation:

Tells the delegate when the interface orientation of the status bar has changed.

Deprecated
- application:willChangeStatusBarFrame:

Tells the delegate when the frame of the status bar is about to change.

Deprecated
- application:didChangeStatusBarFrame:

Tells the delegate when the frame of the status bar has changed.

Deprecated
UIInterfaceOrientation

The orientation of the app's user interface.

UIInterfaceOrientationMask

These constants are mask bits for specifying a view controller’s supported interface orientations.

UIApplicationInvalidInterfaceOrientationException

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

Providing a Window for Storyboarding

window

The window to use when presenting a storyboard.

Deprecated Symbols

- application:didRegisterUserNotificationSettings:

Called to tell the delegate the types of local and remote notifications that can be used to get the user’s attention.

Deprecated
- application:didReceiveLocalNotification:

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

Deprecated
- application:didReceiveRemoteNotification:

Called when your app has received a remote notification.

Deprecated
- application:handleActionWithIdentifier:forLocalNotification:completionHandler:

Called when your app has been activated because user selected a custom action from the alert panel of a local notification.

Deprecated
- application:handleActionWithIdentifier:forLocalNotification:withResponseInfo:completionHandler:

Called when your app has been activated by the user selecting an action from a local notification.

Deprecated
- application:handleActionWithIdentifier:forRemoteNotification:completionHandler:

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

Deprecated
- application:handleActionWithIdentifier:forRemoteNotification:withResponseInfo:completionHandler:

Called when your app has been activated by the user selecting an action from a remote notification.

Deprecated
- application:handleOpenURL:

Asks the delegate to open a resource identified by URL.

Deprecated
- application:openURL:sourceApplication:annotation:

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

Deprecated

Relationships

Inherits From

See Also

Life Cycle

Managing Your App's Life Cycle

Respond to system notifications when your app is in the foreground or background, and handle other significant system-related events.

Responding to the Launch of Your App

Initialize your app’s data structures, prepare your app to run, and respond to any launch-time requests from the system.

UIApplication

The centralized point of control and coordination for apps running in iOS.

Scenes

Manage multiple instances of your app’s UI simultaneously, and direct resources to the appropriate instance of your UI.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software