UIApplicationDelegate
A set of methods to manage shared behaviors for your app.
Declaration
@MainActor protocol UIApplicationDelegate : NSObjectProtocolMentioned in
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’s 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 aren’t 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.
For information on what to do when your app enters the foreground, see Preparing your UI to run in the foreground.
For information on what to do when your app enters the background, see Preparing your UI to run in the background.
For general information about the life cycle of your app, see Managing your app’s life cycle.
Topics
Initializing the app
application(_:willFinishLaunchingWithOptions:)application(_:didFinishLaunchingWithOptions:)UIApplication.LaunchOptionsKeydidFinishLaunchingNotification
Configuring and discarding scenes
Responding to app life-cycle events
applicationDidBecomeActive(_:)applicationWillResignActive(_:)applicationDidEnterBackground(_:)applicationWillEnterForeground(_:)applicationWillTerminate(_:)didBecomeActiveNotificationdidEnterBackgroundNotificationwillEnterForegroundNotificationwillResignActiveNotificationwillTerminateNotification
Responding to environment changes
applicationProtectedDataDidBecomeAvailable(_:)applicationProtectedDataWillBecomeUnavailable(_:)applicationDidReceiveMemoryWarning(_:)applicationSignificantTimeChange(_:)protectedDataDidBecomeAvailableNotificationprotectedDataWillBecomeUnavailableNotificationdidReceiveMemoryWarningNotificationsignificantTimeChangeNotification
Managing app state restoration
application(_:shouldSaveSecureApplicationState:)application(_:shouldRestoreSecureApplicationState:)application(_:viewControllerWithRestorationIdentifierPath:coder:)application(_:willEncodeRestorableStateWith:)application(_:didDecodeRestorableStateWith:)stateRestorationBundleVersionKeystateRestorationSystemVersionKeystateRestorationTimestampKeystateRestorationUserInterfaceIdiomKeystateRestorationViewControllerStoryboardKey
Downloading data in the background
Handling remote notification registration
application(_:didRegisterForRemoteNotificationsWithDeviceToken:)application(_:didFailToRegisterForRemoteNotificationsWithError:)application(_:didReceiveRemoteNotification:fetchCompletionHandler:)
Continuing user activity and handling quick actions
application(_:willContinueUserActivityWithType:)application(_:continue:restorationHandler:)application(_:didUpdate:)application(_:didFailToContinueUserActivityWithType:error:)application(_:performActionFor:completionHandler:)
Interacting with WatchKit
Interacting with HealthKit
Opening a URL-specified resource
Disallowing specified app extension types
Handling SiriKit intents
Handling CloudKit invitations
Localizing keyboard shortcuts
Managing interface geometry
application(_:supportedInterfaceOrientationsFor:)UIInterfaceOrientationUIInterfaceOrientationMaskinvalidInterfaceOrientationException