gpt4 book ai didi

swift - SceneDelegate 和 AppDelegate 的区别

转载 作者:IT王子 更新时间:2023-10-29 05:42:24 27 4
gpt4 key购买 nike

在我的 SwiftUI 项目中,我看到了 AppDelegate 文件以及一个 SceneDelegate 文件。

它们之间有什么区别?

例如SceneDelegate中的方法之间

scene(_:willConnectTo:options:)

并且在 AppDelegate

application(_:didFinishLaunchingWithOptions:)

最佳答案

这两个文件旨在根据运行整个应用程序所需的工作以及支持在后台明显运行的一个“实例”所需的工作来划分工作。这类似于一次配置数据库,但通过窗口显示不同的值集。

您可以将它们视为全局版本和私有(private)版本。一个是共享的,另一个仅限于个人所有者。在某种程度上,它们正是您所期望的名称。

Multi-window support is happening

Next time you create a new Xcode project you’ll see your AppDelegate has split in two: AppDelegate.swift and SceneDelegate.swift. This is a result of the new multi-window support that landed with iPadOS, and effectively splits the work of the app delegate in two.

From iOS 13 onwards, your app delegate should:

  1. Set up any data that you need for the duration of the app.
  2. Respond to any events that focus on the app, such as a file being shared with you.
  3. Register for external services, such as push notifications.
  4. Configure your initial scenes.

In contrast, scene delegates are there to handle one instance of your app’s user interface. So, if the user has created two windows showing your app, you have two scenes, both backed by the same app delegate.

Keep in mind that these scenes are designed to work independently from each other. So, your application no longer moves to the background, but instead individual scenes do – the user might move one to the background while keeping another open.

https://www.hackingwithswift.com/articles/193/whats-new-in-ios-13 提供

关于swift - SceneDelegate 和 AppDelegate 的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56498099/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com