Protocol
A set of methods that you use to manage shared behaviors for your app.
--一组用于app公共行为的方法。
protocol UIApplicationDelegate
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.
--你的app delegate对象管理你的app的公共行为。app委托实际上是app的根对象,它与UIApplication一起管理 与系统的一些交互。与UIApplication对象一样,UIKit在app启动周期的早期创建app delegate对象,所以app delegate 对象是一直存在的。
Use your app delegate object to handle the following tasks:
--使用你的app delegate 方法处理以下任务:
Initializing your app’s central data structures.
--初始化app的中心数据结构。
Configuring your app’s scenes.
--配置app的scene
Responding to notifications originating from outside the app, such as low-memory warnings, download completion notifications, and more.
--响应来自app外部的通知,如内存不足警告、下载完成通知等。
Responding to events that target the app itself, and are not specific to your app’s scenes, views, or view controllers.
--响应针对app本身的事件,而不是特定于app的scene、view或vc的事件。
Registering for any required services at launch time, such as Apple Push Notification service.
--在启动时注册所有必须的服务,如Apple的推送通知服务
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.
--有关如何在启动时使用app delegate对象初始化app的详细信息,请参阅超链接:响应应用程序的启动。
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.
--在ios12或更早的版本中,你使用app委托来管理app中的主要生命周期事件。具体来说,在进入前台或移动到后台状态时,你使用app委托的方法来更新你的app。
For information on what to do when your app enters the foreground, see Preparing Your UI to Run in the Foreground.
--有关app进入前台状态时要执行的操作的信息,请参阅超链接:准备UI在前台运行。
For information on what to do when your app enters the background, see Preparing Your UI to Run in the Background.
--有关app进入后台状态时要执行的操作的信息,请参阅超链接:准备要在后台运行的UI。
For general information about the life cycle of your app, see Managing Your App's Life Cycle.
--有关应用程序生命周期的一般信息,请参阅超链接:管理应用程序的生命周期。
Tells the delegate that the launch process has begun but that state restoration has not yet occurred.
Tells the delegate that the launch process is almost done and the app is almost ready to run.
struct UIApplication.LaunchOptionsKey
Keys used to access values in the launch options dictionary passed to your app at initialization time.
func applicationDidFinishLaunching(UIApplication)
Tells the delegate when the app has finished launching. Don’t use. Instead, use application(_:didFinishLaunchingWithOptions:)
.
class let didFinishLaunchingNotification: NSNotification.Name
Posted immediately after the app finishes launching.
Returns the configuration data for UIKit to use when creating a new scene.
func application(UIApplication, didDiscardSceneSessions: Set<UISceneSession>)
Tells the delegate that the user closed one or more of the app's scenes from the app switcher.
func applicationDidBecomeActive(UIApplication)
Tells the delegate that the app has become active.
func applicationWillResignActive(UIApplication)
Tells the delegate that the app is about to become inactive.
func applicationDidEnterBackground(UIApplication)
Tells the delegate that the app is now in the background.
func applicationWillEnterForeground(UIApplication)
Tells the delegate that the app is about to enter the foreground.
func applicationWillTerminate(UIApplication)
Tells the delegate when the app is about to terminate.
class let didBecomeActiveNotification: NSNotification.Name
Posted when the app becomes active.
class let didEnterBackgroundNotification: NSNotification.Name
Posted when the app enters the background.
class let willEnterForegroundNotification: NSNotification.Name
Posted shortly before an app leaves the background state on its way to becoming the active app.
class let willResignActiveNotification: NSNotification.Name
Posted when the app is no longer active and loses focus.
class let willTerminateNotification: NSNotification.Name
Posted when the app is about to terminate.
func applicationProtectedDataDidBecomeAvailable(UIApplication)
Tells the delegate that protected files are available now.
func applicationProtectedDataWillBecomeUnavailable(UIApplication)
Tells the delegate that the protected files are about to become unavailable.
func applicationDidReceiveMemoryWarning(UIApplication)
Tells the delegate when the app receives a memory warning from the system.
func applicationSignificantTimeChange(UIApplication)
Tells the delegate when there is a significant change in the time.
class let protectedDataDidBecomeAvailableNotification: NSNotification.Name
Posted when the protected files become available for your code to access.
class let protectedDataWillBecomeUnavailableNotification: NSNotification.Name
Posted shortly before protected files are locked down and become inaccessible.
class let didReceiveMemoryWarningNotification: NSNotification.Name
Posted when the app receives a warning from the operating system about low memory availability.
class let significantTimeChangeNotification: NSNotification.Name
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.
func application(UIApplication, shouldSaveApplicationState: NSCoder) -> Bool
Asks the delegate whether the app’s state should be preserved.
func application(UIApplication, shouldRestoreApplicationState: NSCoder) -> Bool
Asks the delegate whether the app’s saved state information should be restored.
Asks the delegate to provide the specified view controller.
func application(UIApplication, willEncodeRestorableStateWith: NSCoder)
Tells your delegate to save any high-level state information at the beginning of the state preservation process.
func application(UIApplication, didDecodeRestorableStateWith: NSCoder)
Tells your delegate to restore any high-level state information as part of the state restoration process.
class let stateRestorationBundleVersionKey: String
The version of your app responsible for creating the restoration archive.
class let stateRestorationSystemVersionKey: String
The version of the system on which your app created the restoration archive.
class let stateRestorationTimestampKey: String
The time at which your app created the restoration archive.
class let stateRestorationUserInterfaceIdiomKey: String
The user interface idiom that was in effect when your app created the restoration archive.
class let stateRestorationViewControllerStoryboardKey: String
A reference to the storyboard that contains the view controller.
Tells the app that it can begin a fetch operation if it has data to download.
Tells the delegate that events related to a URL session are waiting to be processed.
Constants that indicate the result of a background fetch operation.
func application(UIApplication, didRegisterForRemoteNotificationsWithDeviceToken: Data)
Tells the delegate that the app successfully registered with Apple Push Notification service (APNs).
func application(UIApplication, didFailToRegisterForRemoteNotificationsWithError: Error)
Sent to the delegate when Apple Push Notification service cannot successfully complete the registration process.
Tells the app that a remote notification arrived that indicates there is data to be fetched.
func application(UIApplication, willContinueUserActivityWithType: String) -> Bool
Tells the delegate if your app takes responsibility for notifying users when a continuation activity takes longer than expected.
Tells the delegate that the data for continuing an activity is available.
func application(UIApplication, didUpdate: NSUserActivity)
Tells the delegate that the activity was updated.
func application(UIApplication, didFailToContinueUserActivityWithType: String, error: Error)
Tells the delegate that the activity could not be continued.
Called when the user selects a Home screen quick action for your app, except when you’ve intercepted the interaction in a launch method.
Asks the delegate to respond to a request from a paired watchOS app.
func applicationShouldRequestHealthAuthorization(UIApplication)
Called when your app should ask the user for access to his or her HealthKit data.
func application(UIApplication, open: URL, options: [UIApplication.OpenURLOptionsKey : Any]) -> Bool
Asks the delegate to open a resource specified by a URL, and provides a dictionary of launch options.
struct UIApplication.OpenURLOptionsKey
Keys used to access values in the options dictionary when opening a URL.
Asks the delegate to grant permission to use app extensions that are based on a specified extension point identifier.
struct UIApplication.ExtensionPointIdentifier
static let keyboard: UIApplication.ExtensionPointIdentifier
The identifier for custom keyboards.
func application(UIApplication, handle: INIntent, completionHandler: (INIntentResponse) -> Void)
Asks the delegate to handle the specified SiriKit intent directly.
func application(UIApplication, userDidAcceptCloudKitShareWith: CKShareMetadata)
Tells the delegate that the app now has access to shared information in CloudKit.
Asks the delegate for the interface orientations to use for the view controllers in the specified window.
Tells the delegate when the interface orientation of the status bar is about to change.
Deprecatedfunc application(UIApplication, didChangeStatusBarOrientation: UIInterfaceOrientation)
Tells the delegate when the interface orientation of the status bar has changed.
Deprecatedfunc application(UIApplication, willChangeStatusBarFrame: CGRect)
Tells the delegate when the frame of the status bar is about to change.
Deprecatedfunc application(UIApplication, didChangeStatusBarFrame: CGRect)
Tells the delegate when the frame of the status bar has changed.
Deprecatedenum UIInterfaceOrientation
The orientation of the app's user interface.
struct UIInterfaceOrientationMask
These constants are mask bits for specifying a view controller’s supported interface orientations.
class let invalidInterfaceOrientationException: NSExceptionName
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.
The window to use when presenting a storyboard.
func application(UIApplication, didRegister: UIUserNotificationSettings)
Called to tell the delegate the types of local and remote notifications that can be used to get the user’s attention.
Deprecatedfunc application(UIApplication, didReceive: UILocalNotification)
Sent to the delegate when a running app receives a local notification.
Deprecatedfunc application(UIApplication, didReceiveRemoteNotification: [AnyHashable : Any])
Called when your app has received a remote notification.
Called when your app has been activated because user selected a custom action from the alert panel of a local notification.
Called when your app has been activated by the user selecting an action from a local notification.
Tells the app delegate to perform the custom action specified by a remote notification.
Called when your app has been activated by the user selecting an action from a remote notification.
Deprecatedfunc application(UIApplication, handleOpen: URL) -> Bool
Asks the delegate to open a resource identified by URL.
Deprecatedfunc application(UIApplication, open: URL, sourceApplication: String?, annotation: Any) -> Bool
Asks the delegate to open a resource identified by a URL.
Deprecated
func application(UIApplication, shouldRestoreSecureApplicationState: NSCoder) -> Bool
func application(UIApplication, shouldSaveSecureApplicationState: NSCoder) -> Bool
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.
The centralized point of control and coordination for apps running in iOS.
Manage multiple instances of your app’s UI simultaneously, and direct resources to the appropriate instance of your UI.