application(:didDiscardSceneSessions:): This function is called whenever a user discards a scene (such as swiping it away in the multitasking window).
SceneDelegate.swift
Whereas the AppDelegate.swift
file is responsible for handling your app life cycle, the SceneDelegate.swift
file is responsible for your scene's life cycle.
The SceneDelegate.swift
file contains the following default functions:
scene(_:willConnectTo:options:)
sceneDidDisconnect(_:)
sceneDidBecomeActive(_:)
sceneWillResignActive(_:)
sceneWillEnterForeground(_:)
sceneDidEnterBackground(_:)
The scene(_:willConnectTo:options:)
function is called when a scene is added to the app (in simple terms, when your UI is shown). Here, you load the content of the file named ContentView
(which is what you've modified earlier in the ContentView.swift
file):
func scene(_ scene: UIScene, willConnectTo session:
UISceneSession, options connectionOptions:
UIScene.ConnectionOptions) {
let contentView = ContentView()
if let windowScene = scene as? UIWindowScene {
let window = UIWindow(windowScene:
windowScene)
window.rootViewController =
UIHostingController(rootView: contentView)
self.window = window
window.makeKeyAndVisible()
}
}
In short, you use AppDelegate.swift
to perform setup needed for the duration of the app. You also use it to handle events that focus on the app, as well as registered for external services like push notifications. The SceneDelegate.swift
, on the other hand, is designed to handle events for multi-window OS (iPadOS), which supports multiple instances of your app’s UI.
Конец ознакомительного фрагмента.
Текст предоставлен ООО «ЛитРес».
Прочитайте эту книгу целиком, купив полную легальную версию на ЛитРес.
Безопасно оплатить книгу можно банковской картой Visa, MasterCard, Maestro, со счета мобильного телефона, с платежного терминала, в салоне МТС или Связной, через PayPal, WebMoney, Яндекс.Деньги, QIWI Кошелек, бонусными картами или другим удобным Вам способом.