0403--iOS之UIApplicationDelegate协议

Protocol

UIApplicationDelegate

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

       --一组用于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.

      --你的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的详细信息,请参阅超链接:响应应用程序的启动。

 

Life Cycle Management in iOS 12 and Earlier            --iOS 12及更早版本中的生命周期管理

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.
       --有关应用程序生命周期的一般信息,请参阅超链接:管理应用程序的生命周期。

 

Topics

Initializing the App              --初始化app

func application(UIApplication, willFinishLaunchingWithOptions: [UIApplication.LaunchOptionsKey : Any]?) -> Bool

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

func application(UIApplication, didFinishLaunchingWithOptions: [UIApplication.LaunchOptionsKey : Any]?) -> Bool

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.

 

Configuring and Discarding Scenes                        --配置和删除scene

func application(UIApplication, configurationForConnecting: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration

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.

Responding to App Life-Cycle Events                --响应app的生命事件

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.

 

Responding to Environment Changes                              --响应环境的改变

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.

 

Managing App State Restoration                      --管理app的状态恢复

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.

func application(UIApplication, viewControllerWithRestorationIdentifierPath: [String], coder: NSCoder) -> UIViewController?

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.

 

Downloading Data in the Background                      --在后台状态时下载数据

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

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

Deprecatedfunc application(UIApplication, handleEventsForBackgroundURLSession: String, completionHandler: () -> Void)

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

enum UIBackgroundFetchResult

Constants that indicate the result of a background fetch operation.

 

Handling Remote Notification Registration                        --处理远程通知的注册

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.

func application(UIApplication, didReceiveRemoteNotification: [AnyHashable : Any], fetchCompletionHandler: (UIBackgroundFetchResult) -> Void)

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

 

Continuing User Activity and Handling Quick Actions              --继续的用户活动和处理快速操作

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.

func application(UIApplication, continue: NSUserActivity, restorationHandler: ([UIUserActivityRestoring]?) -> Void) -> Bool

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.

func application(UIApplication, performActionFor: UIApplicationShortcutItem, completionHandler: (Bool) -> Void)

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                        --与WatchKit交互

func application(UIApplication, handleWatchKitExtensionRequest: [AnyHashable : Any]?, reply: ([AnyHashable : Any]?) -> Void)

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

 

Interacting With HealthKit                       --与HealthKit互动

func applicationShouldRequestHealthAuthorization(UIApplication)

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

 

Opening a URL-Specified Resource                              --打开URL指定的资源

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.

 

Disallowing Specified App Extension Types                      --禁用指定的app扩展类型

func application(UIApplication, shouldAllowExtensionPointIdentifier: UIApplication.ExtensionPointIdentifier) -> Bool

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.

 

Handling SiriKit Intents                                        --处理SiriKit意图

func application(UIApplication, handle: INIntent, completionHandler: (INIntentResponse) -> Void)

Asks the delegate to handle the specified SiriKit intent directly.

 

Handling CloudKit Invitations                   --处理CloudKit邀请            

func application(UIApplication, userDidAcceptCloudKitShareWith: CKShareMetadata)

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

 

Managing Interface Geometry                 --管理界面几何图形

func application(UIApplication, supportedInterfaceOrientationsFor: UIWindow?) -> UIInterfaceOrientationMask

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

func application(UIApplication, willChangeStatusBarOrientation: UIInterfaceOrientation, duration: TimeInterval)

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.

 

Providing a Window for Storyboarding                         --为故事板提供一个window

var window: UIWindow?

The window to use when presenting a storyboard.

 

Deprecated Symbols                       --弃用的特性

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.

Deprecatedfunc application(UIApplication, handleActionWithIdentifier: String?, for: UILocalNotification, completionHandler: () -> Void)

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

Deprecatedfunc application(UIApplication, handleActionWithIdentifier: String?, for: UILocalNotification, withResponseInfo: [AnyHashable : Any], completionHandler: () -> Void)

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

Deprecatedfunc application(UIApplication, handleActionWithIdentifier: String?, forRemoteNotification: [AnyHashable : Any], completionHandler: () -> Void)

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

Deprecatedfunc application(UIApplication, handleActionWithIdentifier: String?, forRemoteNotification: [AnyHashable : Any], withResponseInfo: [AnyHashable : Any], completionHandler: () -> Void)

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

 

Instance Methods                             --实例的方法

func application(UIApplication, shouldRestoreSecureApplicationState: NSCoder) -> Bool

func application(UIApplication, shouldSaveSecureApplicationState: NSCoder) -> Bool

Relationships

Inherits From

NSObjectProtocol

Inherited By

CPApplicationDelegate

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.

class 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.

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值